diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index e2ac095..5d7bad6 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -62,6 +62,10 @@ This affects clamping window within the visible area: with this option enabled title bars need to be visible. (#899) - Window: Fixed using SetNextWindowPos() on a child window (which wasn't really documented) position the cursor as expected in the parent window, so there is no mismatch between the layout in parent and the position of the child window. +- Error recovery: Extraneous/undesired calls to End() are now being caught by an assert in the End() function itself + at the call site (instead of being reported in EndFrame). Past the assert, they don't lead to crashes any more. (#1651) +- Error recovery: Missing calls to End(), pass the assert, should not lead to crashes or to the fallback Debug window + appearing on screen, (#1651). - IO: Added BackendPlatformUserData, BackendRendererUserData, BackendLanguageUserData void* for storage use by back-ends. - Style: Tweaked default value of style.DisplayWindowPadding from (20,20) to (19,19) so the default style as a value which is the same as the title bar height. diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index e2ac095..5d7bad6 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -62,6 +62,10 @@ This affects clamping window within the visible area: with this option enabled title bars need to be visible. (#899) - Window: Fixed using SetNextWindowPos() on a child window (which wasn't really documented) position the cursor as expected in the parent window, so there is no mismatch between the layout in parent and the position of the child window. +- Error recovery: Extraneous/undesired calls to End() are now being caught by an assert in the End() function itself + at the call site (instead of being reported in EndFrame). Past the assert, they don't lead to crashes any more. (#1651) +- Error recovery: Missing calls to End(), pass the assert, should not lead to crashes or to the fallback Debug window + appearing on screen, (#1651). - IO: Added BackendPlatformUserData, BackendRendererUserData, BackendLanguageUserData void* for storage use by back-ends. - Style: Tweaked default value of style.DisplayWindowPadding from (20,20) to (19,19) so the default style as a value which is the same as the title bar height. diff --git a/imgui.cpp b/imgui.cpp index 1629eba..f33d7d5 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3555,6 +3555,9 @@ return; IM_ASSERT(g.FrameScopeActive && "Forgot to call ImGui::NewFrame()?"); + g.FrameScopeActive = false; + g.FrameCountEnded = g.FrameCount; + // Notify OS when our Input Method Editor cursor has moved (e.g. CJK inputs using Microsoft IME) if (g.IO.ImeSetInputScreenPosFn && ImLengthSqr(g.PlatformImeLastPos - g.PlatformImePos) > 0.0001f) { @@ -3567,9 +3570,15 @@ if (g.CurrentWindowStack.Size != 1) { if (g.CurrentWindowStack.Size > 1) + { IM_ASSERT(g.CurrentWindowStack.Size == 1 && "Mismatched Begin/BeginChild vs End/EndChild calls: did you forget to call End/EndChild?"); + while (g.CurrentWindowStack.Size > 1) // FIXME-ERRORHANDLING + End(); + } else + { IM_ASSERT(g.CurrentWindowStack.Size == 1 && "Mismatched Begin/BeginChild vs End/EndChild calls: did you call End/EndChild too much?"); + } } // Hide implicit/fallback "Debug" window if it hasn't been used @@ -3665,9 +3674,6 @@ g.IO.MouseWheel = g.IO.MouseWheelH = 0.0f; memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters)); memset(g.IO.NavInputs, 0, sizeof(g.IO.NavInputs)); - - g.FrameScopeActive = false; - g.FrameCountEnded = g.FrameCount; } void ImGui::Render() @@ -5251,6 +5257,13 @@ void ImGui::End() { ImGuiContext& g = *GImGui; + + if (g.CurrentWindowStack.Size <= 1 && g.FrameScopeActive) + { + IM_ASSERT(g.CurrentWindowStack.Size > 1 && "Calling End() too many times!"); + return; // FIXME-ERRORHANDLING + } + ImGuiWindow* window = g.CurrentWindow; if (window->DC.ColumnsSet != NULL)