Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table is Null when scrolling down on the window #8314

Closed
Icaka00 opened this issue Jan 12, 2025 · 2 comments
Closed

Table is Null when scrolling down on the window #8314

Icaka00 opened this issue Jan 12, 2025 · 2 comments

Comments

@Icaka00
Copy link

Icaka00 commented Jan 12, 2025

Version/Branch of Dear ImGui:

Version 1.91.6, Branch: docking

Back-ends:

imgui_impl_XXX.cpp + imgui_impl_XXX.cpp

Compiler, OS:

Windows 10 + MSVC2022

Full config/build information:

No response

Details:

I have a table that is only 2 columns. One is full of Tree Nodes, and the other is just a child window with a text inside. When i open some of them, just to take enough space to scroll down, and when i do so, the program crashes and gives me an error for accessing NULL* in EndTable()

Screenshots/Video:

image

Untitled.design.mp4

Minimal, Complete and Verifiable Example code:

if (ImGui::Begin("Assets", &showAssets))
{
	if (ImGui::BeginTable("assets_table", 2, ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersInnerV))
	{
		ImGui::TableSetupColumn("Folders", ImGuiTableColumnFlags_WidthFixed, 150.0f);
		ImGui::TableSetupColumn("Files", ImGuiTableColumnFlags_WidthStretch);

		ImGui::TableNextRow();
		ImGui::TableSetColumnIndex(0);

		// Display directories
		if (ImGui::TreeNode("Folder1"))
		{
			ImGui::TreeNodeEx("1-file1", ImGuiTreeNodeFlags_Leaf); ImGui::TreePop();
			ImGui::TreeNodeEx("1-file2", ImGuiTreeNodeFlags_Leaf); ImGui::TreePop();
			ImGui::TreeNodeEx("1-file3", ImGuiTreeNodeFlags_Leaf); ImGui::TreePop();

			ImGui::TreePop();
		}
		if (ImGui::TreeNode("Folder3"))
		{
			ImGui::TreeNodeEx("2-file1", ImGuiTreeNodeFlags_Leaf); ImGui::TreePop();
			ImGui::TreeNodeEx("2-file2", ImGuiTreeNodeFlags_Leaf); ImGui::TreePop();
			ImGui::TreeNodeEx("2-file3", ImGuiTreeNodeFlags_Leaf); ImGui::TreePop();

			ImGui::TreePop();
		}
		if (ImGui::TreeNode("Folder2"))
		{
			ImGui::TreeNodeEx("3-file1", ImGuiTreeNodeFlags_Leaf); ImGui::TreePop();
			ImGui::TreeNodeEx("3-file2", ImGuiTreeNodeFlags_Leaf); ImGui::TreePop();
			ImGui::TreeNodeEx("3-file3", ImGuiTreeNodeFlags_Leaf); ImGui::TreePop();

			ImGui::TreePop();
		}

		ImGui::TableSetColumnIndex(1);

		if (ImGui::GetContentRegionMax().x > 200)
		{
			if (ImGui::BeginChild("Path Viewer"))
			{
				ImGui::Text("TEST");
				ImGui::EndChild();
			}
		}

		ImGui::EndTable();
	}
        ImGui::End();
}
@ocornut
Copy link
Owner

ocornut commented Jan 12, 2025

if (ImGui::BeginChild("Path Viewer"))
{
ImGui::Text("TEST");
ImGui::EndChild();
}

Your error is here, both Begin() and BeginChild() requires their respective End function to always be called.

What is happening is that when the child function is entirely out of view it is returning false, and there you are then not calling EndChild(), and effectively the EndTable() is called within the child.

So, it is mistake in your code. There is an assert to catch it at the top of the EndTable() function.
It is extremely important that you never write imgui code with IM_ASSERT() disabled. If calling IM_ASSERT(false) doesn’t immediately crash/break you into a debugger, you should get it fixed otherwise you are using the lib without error checking.

ocornut added a commit that referenced this issue Jan 12, 2025
@ocornut
Copy link
Owner

ocornut commented Jan 12, 2025

Pushed 1d96282 "Turned common EndTable() and other TableXXX functions fail cases into recoverable errors."
This will more clearly print the current location (in your case it would state that you are inside "Path viewer") which is likely to help narrowing down that issue.

@ocornut ocornut closed this as completed Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants