Skip to content

Commit fbc93de

Browse files
committed
Internal: Refactor: Moved NewFrameSanityChecks as ErrorCheckNewFrameSanityChecks()
1 parent ccf0cc8 commit fbc93de

File tree

1 file changed

+38
-35
lines changed

1 file changed

+38
-35
lines changed

imgui.cpp

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,8 @@ static ImGuiWindow* NavRestoreLastChildNavWindow(ImGuiWindow* window);
935935
static int FindWindowFocusIndex(ImGuiWindow* window);
936936

937937
// Error Checking
938-
static void ErrorCheckEndFrame();
938+
static void ErrorCheckNewFrameSanityChecks();
939+
static void ErrorCheckEndFrameSanityChecks();
939940
static void ErrorCheckBeginEndCompareStacksSize(ImGuiWindow* window, bool write);
940941

941942
// Misc
@@ -3675,35 +3676,6 @@ void ImGui::UpdateHoveredWindowAndCaptureFlags()
36753676
g.IO.WantTextInput = (g.WantTextInputNextFrame != -1) ? (g.WantTextInputNextFrame != 0) : false;
36763677
}
36773678

3678-
static void NewFrameSanityChecks()
3679-
{
3680-
ImGuiContext& g = *GImGui;
3681-
3682-
// Check user data
3683-
// (We pass an error message in the assert expression to make it visible to programmers who are not using a debugger, as most assert handlers display their argument)
3684-
IM_ASSERT(g.Initialized);
3685-
IM_ASSERT((g.IO.DeltaTime > 0.0f || g.FrameCount == 0) && "Need a positive DeltaTime!");
3686-
IM_ASSERT((g.FrameCount == 0 || g.FrameCountEnded == g.FrameCount) && "Forgot to call Render() or EndFrame() at the end of the previous frame?");
3687-
IM_ASSERT(g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f && "Invalid DisplaySize value!");
3688-
IM_ASSERT(g.IO.Fonts->Fonts.Size > 0 && "Font Atlas not built. Did you call io.Fonts->GetTexDataAsRGBA32() / GetTexDataAsAlpha8() ?");
3689-
IM_ASSERT(g.IO.Fonts->Fonts[0]->IsLoaded() && "Font Atlas not built. Did you call io.Fonts->GetTexDataAsRGBA32() / GetTexDataAsAlpha8() ?");
3690-
IM_ASSERT(g.Style.CurveTessellationTol > 0.0f && "Invalid style setting!");
3691-
IM_ASSERT(g.Style.CircleSegmentMaxError > 0.0f && "Invalid style setting!");
3692-
IM_ASSERT(g.Style.Alpha >= 0.0f && g.Style.Alpha <= 1.0f && "Invalid style setting. Alpha cannot be negative (allows us to avoid a few clamps in color computations)!");
3693-
IM_ASSERT(g.Style.WindowMinSize.x >= 1.0f && g.Style.WindowMinSize.y >= 1.0f && "Invalid style setting.");
3694-
IM_ASSERT(g.Style.WindowMenuButtonPosition == ImGuiDir_None || g.Style.WindowMenuButtonPosition == ImGuiDir_Left || g.Style.WindowMenuButtonPosition == ImGuiDir_Right);
3695-
for (int n = 0; n < ImGuiKey_COUNT; n++)
3696-
IM_ASSERT(g.IO.KeyMap[n] >= -1 && g.IO.KeyMap[n] < IM_ARRAYSIZE(g.IO.KeysDown) && "io.KeyMap[] contains an out of bound value (need to be 0..512, or -1 for unmapped key)");
3697-
3698-
// Perform simple check: required key mapping (we intentionally do NOT check all keys to not pressure user into setting up everything, but Space is required and was only recently added in 1.60 WIP)
3699-
if (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard)
3700-
IM_ASSERT(g.IO.KeyMap[ImGuiKey_Space] != -1 && "ImGuiKey_Space is not mapped, required for keyboard navigation.");
3701-
3702-
// Perform simple check: the beta io.ConfigWindowsResizeFromEdges option requires back-end to honor mouse cursor changes and set the ImGuiBackendFlags_HasMouseCursors flag accordingly.
3703-
if (g.IO.ConfigWindowsResizeFromEdges && !(g.IO.BackendFlags & ImGuiBackendFlags_HasMouseCursors))
3704-
g.IO.ConfigWindowsResizeFromEdges = false;
3705-
}
3706-
37073679
static ImGuiKeyModFlags GetMergedKeyModFlags()
37083680
{
37093681
ImGuiContext& g = *GImGui;
@@ -3725,7 +3697,7 @@ void ImGui::NewFrame()
37253697
#endif
37263698

37273699
// Check and assert for various common IO and Configuration mistakes
3728-
NewFrameSanityChecks();
3700+
ErrorCheckNewFrameSanityChecks();
37293701

37303702
// Load settings on first frame, save settings when modified (after a delay)
37313703
UpdateSettings();
@@ -4171,19 +4143,21 @@ void ImGui::EndFrame()
41714143
{
41724144
ImGuiContext& g = *GImGui;
41734145
IM_ASSERT(g.Initialized);
4174-
if (g.FrameCountEnded == g.FrameCount) // Don't process EndFrame() multiple times.
4146+
4147+
// Don't process EndFrame() multiple times.
4148+
if (g.FrameCountEnded == g.FrameCount)
41754149
return;
41764150
IM_ASSERT(g.WithinFrameScope && "Forgot to call ImGui::NewFrame()?");
41774151

4152+
ErrorCheckEndFrameSanityChecks();
4153+
41784154
// Notify OS when our Input Method Editor cursor has moved (e.g. CJK inputs using Microsoft IME)
41794155
if (g.IO.ImeSetInputScreenPosFn && (g.PlatformImeLastPos.x == FLT_MAX || ImLengthSqr(g.PlatformImeLastPos - g.PlatformImePos) > 0.0001f))
41804156
{
41814157
g.IO.ImeSetInputScreenPosFn((int)g.PlatformImePos.x, (int)g.PlatformImePos.y);
41824158
g.PlatformImeLastPos = g.PlatformImePos;
41834159
}
41844160

4185-
ErrorCheckEndFrame();
4186-
41874161
// Hide implicit/fallback "Debug" window if it hasn't been used
41884162
g.WithinFrameScopeWithImplicitWindow = false;
41894163
if (g.CurrentWindow && !g.CurrentWindow->WriteAccessed)
@@ -6731,7 +6705,36 @@ bool ImGui::DebugCheckVersionAndDataLayout(const char* version, size_t sz_io, si
67316705
return !error;
67326706
}
67336707

6734-
static void ImGui::ErrorCheckEndFrame()
6708+
static void ImGui::ErrorCheckNewFrameSanityChecks()
6709+
{
6710+
ImGuiContext& g = *GImGui;
6711+
6712+
// Check user data
6713+
// (We pass an error message in the assert expression to make it visible to programmers who are not using a debugger, as most assert handlers display their argument)
6714+
IM_ASSERT(g.Initialized);
6715+
IM_ASSERT((g.IO.DeltaTime > 0.0f || g.FrameCount == 0) && "Need a positive DeltaTime!");
6716+
IM_ASSERT((g.FrameCount == 0 || g.FrameCountEnded == g.FrameCount) && "Forgot to call Render() or EndFrame() at the end of the previous frame?");
6717+
IM_ASSERT(g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f && "Invalid DisplaySize value!");
6718+
IM_ASSERT(g.IO.Fonts->Fonts.Size > 0 && "Font Atlas not built. Did you call io.Fonts->GetTexDataAsRGBA32() / GetTexDataAsAlpha8() ?");
6719+
IM_ASSERT(g.IO.Fonts->Fonts[0]->IsLoaded() && "Font Atlas not built. Did you call io.Fonts->GetTexDataAsRGBA32() / GetTexDataAsAlpha8() ?");
6720+
IM_ASSERT(g.Style.CurveTessellationTol > 0.0f && "Invalid style setting!");
6721+
IM_ASSERT(g.Style.CircleSegmentMaxError > 0.0f && "Invalid style setting!");
6722+
IM_ASSERT(g.Style.Alpha >= 0.0f && g.Style.Alpha <= 1.0f && "Invalid style setting. Alpha cannot be negative (allows us to avoid a few clamps in color computations)!");
6723+
IM_ASSERT(g.Style.WindowMinSize.x >= 1.0f && g.Style.WindowMinSize.y >= 1.0f && "Invalid style setting.");
6724+
IM_ASSERT(g.Style.WindowMenuButtonPosition == ImGuiDir_None || g.Style.WindowMenuButtonPosition == ImGuiDir_Left || g.Style.WindowMenuButtonPosition == ImGuiDir_Right);
6725+
for (int n = 0; n < ImGuiKey_COUNT; n++)
6726+
IM_ASSERT(g.IO.KeyMap[n] >= -1 && g.IO.KeyMap[n] < IM_ARRAYSIZE(g.IO.KeysDown) && "io.KeyMap[] contains an out of bound value (need to be 0..512, or -1 for unmapped key)");
6727+
6728+
// Perform simple check: required key mapping (we intentionally do NOT check all keys to not pressure user into setting up everything, but Space is required and was only recently added in 1.60 WIP)
6729+
if (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard)
6730+
IM_ASSERT(g.IO.KeyMap[ImGuiKey_Space] != -1 && "ImGuiKey_Space is not mapped, required for keyboard navigation.");
6731+
6732+
// Perform simple check: the beta io.ConfigWindowsResizeFromEdges option requires back-end to honor mouse cursor changes and set the ImGuiBackendFlags_HasMouseCursors flag accordingly.
6733+
if (g.IO.ConfigWindowsResizeFromEdges && !(g.IO.BackendFlags & ImGuiBackendFlags_HasMouseCursors))
6734+
g.IO.ConfigWindowsResizeFromEdges = false;
6735+
}
6736+
6737+
static void ImGui::ErrorCheckEndFrameSanityChecks()
67356738
{
67366739
ImGuiContext& g = *GImGui;
67376740

0 commit comments

Comments
 (0)