Exception when collapse window with ListBox #3687

Closed
opened 2021-01-01 17:13:05 +00:00 by nikikust · 3 comments
nikikust commented 2021-01-01 17:13:05 +00:00 (Migrated from github.com)

Version: v1.79
Branch: master
OS: Windows 10
Compiler: VS2019

When i try to collapse window with ListBox in it:

"An unhandled exception was thrown: read access violation.
parent_window was nullptr."

изображение

Shown example:

ImGui::Begin("Error test");
ImGui::ListBoxHeader("Test");
ImGui::Selectable("A", false);
ImGui::ListBoxFooter();
ImGui::End();
Version: v1.79 Branch: master OS: Windows 10 Compiler: VS2019 --- When i try to collapse window with ListBox in it: "An unhandled exception was thrown: read access violation. parent_window was nullptr." ![изображение](https://user-images.githubusercontent.com/52621231/103443168-78fe2580-4c6d-11eb-928a-28da0c908f85.png) Shown example: ``` ImGui::Begin("Error test"); ImGui::ListBoxHeader("Test"); ImGui::Selectable("A", false); ImGui::ListBoxFooter(); ImGui::End(); ```
rokups commented 2021-01-01 17:27:47 +00:00 (Migrated from github.com)

Try:

if (ImGui::Begin("Error test"))
{
    ImGui::ListBoxHeader("Test");
    ImGui::Selectable("A", false);
    ImGui::ListBoxFooter();
}
ImGui::End();
Try: ```cpp if (ImGui::Begin("Error test")) { ImGui::ListBoxHeader("Test"); ImGui::Selectable("A", false); ImGui::ListBoxFooter(); } ImGui::End(); ```
nikikust commented 2021-01-03 10:17:01 +00:00 (Migrated from github.com)

It works, but this adds one more strange 'If' to program, also if you have control for open/close of imgui window you will need control for imgui::end too, because you can not open window and this will throw error to too much ::ends. So i think that shouldn't work like you suggested.

It works, but this adds one more strange 'If' to program, also if you have control for open/close of imgui window you will need control for imgui::end too, because you can not open window and this will throw error to too much ::ends. So i think that shouldn't work like you suggested.
ocornut commented 2021-01-03 10:32:32 +00:00 (Migrated from github.com)

but this adds one more strange 'If' to program,

It's not a "strange if", this is how you are supposed to use the Begin() function.

Either way, if you look at the description for ListBoxHeader() it says:

"if the function return true, you can output elements then call ListBoxFooter() afterwards."

And if you look for usage of ListBoxHeader() anywhere in the codebase you'll find that every single use of it is testing the return value. So you should at least do:

ImGui::Begin("Error test");
if (ImGui::ListBoxHeader("Test"))
{
    ImGui::Selectable("A", false);
    ImGui::ListBoxFooter();
}
ImGui::End();

I have reworked the code in ListBoxFooter() to more properly assert with a message to help guide future users.

> but this adds one more strange 'If' to program, It's not a "strange if", this is how you are supposed to use the `Begin()` function. Either way, if you look at the description for `ListBoxHeader()` it says: "if the function return true, you can output elements then call ListBoxFooter() afterwards." And if you look for usage of `ListBoxHeader()` anywhere in the codebase you'll find that every single use of it is testing the return value. So you should at least do: ``` ImGui::Begin("Error test"); if (ImGui::ListBoxHeader("Test")) { ImGui::Selectable("A", false); ImGui::ListBoxFooter(); } ImGui::End(); ``` I have reworked the code in `ListBoxFooter()` to more properly assert with a message to help guide future users.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#3687
No description provided.