Skip to content

Fix unbalanced ImGui::EndPopup in the modal window - #417

Open
buddingmonkey wants to merge 1 commit into
HarbourMasters:develop-splitrockfrom
buddingmonkey:lh/fix-modal-endpopup
Open

Fix unbalanced ImGui::EndPopup in the modal window#417
buddingmonkey wants to merge 1 commit into
HarbourMasters:develop-splitrockfrom
buddingmonkey:lh/fix-modal-endpopup

Conversation

@buddingmonkey

Copy link
Copy Markdown

ImGui::EndPopup() is only legal when the matching BeginPopupModal() call returned true. DrawElement() called it unconditionally, one level outside the "if (ImGui::BeginPopupModal(...))" block, so it also ran on frames where the popup was not open.

That state is trivially reachable. The closePopup branch above calls ImGui::CloseCurrentPopup() and erases the modal from the queue, so on the very next frame BeginPopupModal() returns false, and the old code still called EndPopup(). This pops a window that was never pushed, corrupting ImGui's internal window and ID stacks for the rest of the frame.

Debug builds of ImGui assert on this, and the path is reachable on every platform every single time a modal is dismissed. Moving EndPopup() inside the block keeps the Begin/End pair balanced.


AI assistance was used in preparing this change; the diff and its reasoning were
reviewed and verified by hand before submission.

Comment thread src/port/UI/LighthouseModals.cpp Outdated
@buddingmonkey
buddingmonkey force-pushed the lh/fix-modal-endpopup branch from 6d71d19 to 91b30e2 Compare August 6, 2026 15:57
ImGui::EndPopup() is only legal when the matching BeginPopupModal() call
returned true. DrawElement() called it unconditionally, one level outside
the "if (ImGui::BeginPopupModal(...))" block, so it also ran on frames
where the popup was not open.

That state is trivially reachable. The closePopup branch above calls
ImGui::CloseCurrentPopup() and erases the modal from the queue, so on the
very next frame BeginPopupModal() returns false, and the old code still
called EndPopup(). This pops a window that was never pushed, corrupting
ImGui's internal window and ID stacks for the rest of the frame.

Debug builds of ImGui assert on this, and the path is reachable on every
platform every single time a modal is dismissed. Moving EndPopup() inside
the block keeps the Begin/End pair balanced.
@buddingmonkey
buddingmonkey force-pushed the lh/fix-modal-endpopup branch from 91b30e2 to 66db153 Compare August 6, 2026 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants