diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 0f2e5e4b5..f90950541 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -54,6 +54,7 @@ Other Changes: - Windows: - Fixed a single-axis auto-resizing feedback loop issue with nested containers and varying scrollbar visibility. (#9352) + - Detect and report error when calling End() instead of EndPopup() on a popup. (#9351) - Fonts: - imgui_freetype: add FreeType headers & compiled version in 'About Dear ImGui' details. - Clipper: diff --git a/imgui.cpp b/imgui.cpp index 2df29975e..5beb0fbb0 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4154,7 +4154,7 @@ ImGuiContext::ImGuiContext(ImFontAtlas* shared_font_atlas) IO.Fonts = shared_font_atlas ? shared_font_atlas : IM_NEW(ImFontAtlas)(); if (shared_font_atlas == NULL) IO.Fonts->OwnerContext = this; - WithinEndChildID = 0; + WithinEndChildID = WithinEndPopupID = 0; TestEngine = NULL; InputEventsNextMouseSource = ImGuiMouseSource_Mouse; @@ -8207,6 +8207,8 @@ void ImGui::End() ImGuiWindowStackData& window_stack_data = g.CurrentWindowStack.back(); // Error checking: verify that user doesn't directly call End() on a child window. + if (window->Flags & ImGuiWindowFlags_Popup) + IM_ASSERT_USER_ERROR(g.WithinEndPopupID == window->ID, "Must call EndPopup() and not End()!"); if (window->Flags & ImGuiWindowFlags_ChildWindow) IM_ASSERT_USER_ERROR(g.WithinEndChildID == window->ID, "Must call EndChild() and not End()!"); @@ -12491,10 +12493,13 @@ void ImGui::EndPopup() NavMoveRequestTryWrapping(window, ImGuiNavMoveFlags_LoopY); // Child-popups don't need to be laid out + const ImGuiID backup_within_end_popup_id = g.WithinEndPopupID; const ImGuiID backup_within_end_child_id = g.WithinEndChildID; + g.WithinEndPopupID = window->ID; if (window->Flags & ImGuiWindowFlags_ChildWindow) g.WithinEndChildID = window->ID; End(); + g.WithinEndPopupID = backup_within_end_popup_id; g.WithinEndChildID = backup_within_end_child_id; } diff --git a/imgui_internal.h b/imgui_internal.h index 9cf35194b..bb0b7f3a3 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -2213,6 +2213,7 @@ struct ImGuiContext float CurrentDpiScale; // Current window/viewport DpiScale == CurrentViewport->DpiScale ImDrawListSharedData DrawListSharedData; ImGuiID WithinEndChildID; // Set within EndChild() + ImGuiID WithinEndPopupID; // Set within EndPopup() void* TestEngine; // Test engine user data // Inputs