Made assertion more clear when trying to call Begin() outside of the NewFrame()..EndFrame() scope. (#1987)
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 56643c4..29a736c 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -56,6 +56,7 @@
- IsItemHovered(): Added ImGuiHoveredFlags_AllowWhenDisabled flag to query hovered status on disabled items. (#1940, #211)
- Misc: Added ImGuiMouseCursor_Hand cursor enum + corresponding software cursor. (#1913, 1914) [@aiekick, @ocornut]
- Misc: Tweaked software mouse cursor offset to match the offset of the corresponding Windows 10 cursors.
+ - Made assertion more clear when trying to call Begin() outside of the NewFrame()..EndFrame() scope. (#1987)
- Fixed horizontal mouse wheel not forwarding the request to the parent window if ImGuiWindowFlags_NoScrollWithMouse is set. (#1463, #1380, #1502)
- Fixed a include build issue for Cygwin in non-POSIX (Win32) mode. (#1917, #1319, #276)
- OS/Windows: Fixed missing ImmReleaseContext() call in the default Win32 IME handler. (#1932) [@vby]
diff --git a/imgui.cpp b/imgui.cpp
index 484ad24..d7db96b 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -3883,6 +3883,7 @@
}
g.Time += g.IO.DeltaTime;
+ g.FrameScopeActive = true;
g.FrameCount += 1;
g.TooltipOverrideCount = 0;
g.WindowsActiveCount = 0;
@@ -4421,9 +4422,11 @@
void ImGui::EndFrame()
{
ImGuiContext& g = *GImGui;
- IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame()
+ IM_ASSERT(g.Initialized);
if (g.FrameCountEnded == g.FrameCount) // Don't process EndFrame() multiple times.
return;
+ IM_ASSERT(g.FrameScopeActive && "Forgot to call ImGui::NewFrame()");
+ g.FrameScopeActive = false;
// 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)
@@ -4508,7 +4511,7 @@
void ImGui::Render()
{
ImGuiContext& g = *GImGui;
- IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame()
+ IM_ASSERT(g.Initialized);
if (g.FrameCountEnded != g.FrameCount)
ImGui::EndFrame();
@@ -6212,7 +6215,7 @@
ImGuiContext& g = *GImGui;
const ImGuiStyle& style = g.Style;
IM_ASSERT(name != NULL); // Window name required
- IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame()
+ IM_ASSERT(g.FrameScopeActive); // Forgot to call ImGui::NewFrame()
IM_ASSERT(g.FrameCountEnded != g.FrameCount); // Called ImGui::Render() or ImGui::EndFrame() and haven't called ImGui::NewFrame() again yet
// Find or create
diff --git a/imgui_internal.h b/imgui_internal.h
index 8d4198d..1adfde1 100644
--- a/imgui_internal.h
+++ b/imgui_internal.h
@@ -608,6 +608,7 @@
struct ImGuiContext
{
bool Initialized;
+ bool FrameScopeActive; // Set by NewFrame(), cleared by EndFrame()/Render()
bool FontAtlasOwnedByContext; // Io.Fonts-> is owned by the ImGuiContext and will be destructed along with it.
ImGuiIO IO;
ImGuiStyle Style;
@@ -761,6 +762,7 @@
ImGuiContext(ImFontAtlas* shared_font_atlas) : OverlayDrawList(NULL)
{
Initialized = false;
+ FrameScopeActive = false;
Font = NULL;
FontSize = FontBaseSize = 0.0f;
FontAtlasOwnedByContext = shared_font_atlas ? false : true;