Fix unbalanced ImGui::EndPopup in the modal window - #417
Open
buddingmonkey wants to merge 1 commit into
Open
Conversation
JeodC
reviewed
Aug 6, 2026
buddingmonkey
force-pushed
the
lh/fix-modal-endpopup
branch
from
August 6, 2026 15:57
6d71d19 to
91b30e2
Compare
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
force-pushed
the
lh/fix-modal-endpopup
branch
from
August 6, 2026 16:12
91b30e2 to
66db153
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.