Skip to content

Commit d0750ee

Browse files
committed
Error check: clarified that carriage returns are emitted by our code. Added helper default callback. Comments. (ocornut#1651)
(doesn't affect test engine hook for it as trailing \n are trimmed anyhow)
1 parent 0af2c4e commit d0750ee

File tree

2 files changed

+41
-19
lines changed

2 files changed

+41
-19
lines changed

imgui.cpp

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ CODE
7979
// [SECTION] MAIN CODE (most of the code! lots of stuff, needs tidying up!)
8080
// [SECTION] ID STACK
8181
// [SECTION] INPUTS
82-
// [SECTION] ERROR CHECKING
82+
// [SECTION] ERROR CHECKING, STATE RECOVERY
8383
// [SECTION] ITEM SUBMISSION
8484
// [SECTION] LAYOUT
8585
// [SECTION] SCROLLING
@@ -7734,7 +7734,8 @@ void ImGui::PopItemFlag()
77347734
// - Those can be nested but it cannot be used to enable an already disabled section (a single BeginDisabled(true) in the stack is enough to keep everything disabled)
77357735
// - Visually this is currently altering alpha, but it is expected that in a future styling system this would work differently.
77367736
// - Feedback welcome at https://github.com/ocornut/imgui/issues/211
7737-
// - BeginDisabled(false) essentially does nothing useful but is provided to facilitate use of boolean expressions. If you can avoid calling BeginDisabled(False)/EndDisabled() best to avoid it.
7737+
// - BeginDisabled(false) essentially does nothing useful but is provided to facilitate use of boolean expressions.
7738+
// (as a micro-optimisation if you can avoid calling BeginDisabled(false)/EndDisabled() tens of thousands of times by doing a local check, it won't hurt)
77387739
// - Optimized shortcuts instead of PushStyleVar() + PushItemFlag()
77397740
// - Note: mixing up BeginDisabled() and PushItemFlag(ImGuiItemFlags_Disabled) is currently NOT SUPPORTED.
77407741
void ImGui::BeginDisabled(bool disabled)
@@ -10069,7 +10070,15 @@ bool ImGui::Shortcut(ImGuiKeyChord key_chord, ImGuiInputFlags flags, ImGuiID own
1006910070

1007010071

1007110072
//-----------------------------------------------------------------------------
10072-
// [SECTION] ERROR CHECKING
10073+
// [SECTION] ERROR CHECKING, STATE RECOVERY
10074+
//-----------------------------------------------------------------------------
10075+
// - DebugCheckVersionAndDataLayout() (called via IMGUI_CHECKVERSION() macros)
10076+
// - ErrorCheckUsingSetCursorPosToExtendParentBoundaries()
10077+
// - ErrorCheckNewFrameSanityChecks()
10078+
// - ErrorCheckEndFrameSanityChecks()
10079+
// - ErrorCheckEndFrameRecover()
10080+
// - ErrorCheckEndWindowRecover()
10081+
// - ImGuiStackSizes
1007310082
//-----------------------------------------------------------------------------
1007410083

1007510084
// Verify ABI compatibility between caller code and compiled version of Dear ImGui. This helps detects some build issues.
@@ -10215,6 +10224,15 @@ static void ImGui::ErrorCheckEndFrameSanityChecks()
1021510224
IM_ASSERT_USER_ERROR(g.GroupStack.Size == 0, "Missing EndGroup call!");
1021610225
}
1021710226

10227+
// Default implementation of ImGuiErrorLogCallback that pipe errors to DebugLog: appears in tty + Tools->DebugLog
10228+
void ImGui::ErrorLogCallbackToDebugLog(void*, const char* fmt, ...)
10229+
{
10230+
va_list args;
10231+
va_start(args, fmt);
10232+
ImGui::DebugLogV(fmt, args);
10233+
va_end(args);
10234+
}
10235+
1021810236
// Experimental recovery from incorrect usage of BeginXXX/EndXXX/PushXXX/PopXXX calls.
1021910237
// Must be called during or before EndFrame().
1022010238
// This is generally flawed as we are not necessarily End/Popping things in the right order.
@@ -10235,12 +10253,12 @@ void ImGui::ErrorCheckEndFrameRecover(ImGuiErrorLogCallback log_callback, voi
1023510253
}
1023610254
if (window->Flags & ImGuiWindowFlags_ChildWindow)
1023710255
{
10238-
if (log_callback) log_callback(user_data, "Recovered from missing EndChild() for '%s'", window->Name);
10256+
if (log_callback) log_callback(user_data, "Recovered from missing EndChild() for '%s'\n", window->Name);
1023910257
EndChild();
1024010258
}
1024110259
else
1024210260
{
10243-
if (log_callback) log_callback(user_data, "Recovered from missing End() for '%s'", window->Name);
10261+
if (log_callback) log_callback(user_data, "Recovered from missing End() for '%s'\n", window->Name);
1024410262
End();
1024510263
}
1024610264
}
@@ -10252,7 +10270,7 @@ void ImGui::ErrorCheckEndWindowRecover(ImGuiErrorLogCallback log_callback, vo
1025210270
ImGuiContext& g = *GImGui;
1025310271
while (g.CurrentTable && (g.CurrentTable->OuterWindow == g.CurrentWindow || g.CurrentTable->InnerWindow == g.CurrentWindow))
1025410272
{
10255-
if (log_callback) log_callback(user_data, "Recovered from missing EndTable() in '%s'", g.CurrentTable->OuterWindow->Name);
10273+
if (log_callback) log_callback(user_data, "Recovered from missing EndTable() in '%s'\n", g.CurrentTable->OuterWindow->Name);
1025610274
EndTable();
1025710275
}
1025810276

@@ -10261,32 +10279,32 @@ void ImGui::ErrorCheckEndWindowRecover(ImGuiErrorLogCallback log_callback, vo
1026110279
IM_ASSERT(window != NULL);
1026210280
while (g.CurrentTabBar != NULL) //-V1044
1026310281
{
10264-
if (log_callback) log_callback(user_data, "Recovered from missing EndTabBar() in '%s'", window->Name);
10282+
if (log_callback) log_callback(user_data, "Recovered from missing EndTabBar() in '%s'\n", window->Name);
1026510283
EndTabBar();
1026610284
}
1026710285
while (g.CurrentMultiSelect != NULL && g.CurrentMultiSelect->Storage->Window == window)
1026810286
{
10269-
if (log_callback) log_callback(user_data, "Recovered from missing EndMultiSelect() in '%s'", window->Name);
10287+
if (log_callback) log_callback(user_data, "Recovered from missing EndMultiSelect() in '%s'\n", window->Name);
1027010288
EndMultiSelect();
1027110289
}
1027210290
while (window->DC.TreeDepth > 0)
1027310291
{
10274-
if (log_callback) log_callback(user_data, "Recovered from missing TreePop() in '%s'", window->Name);
10292+
if (log_callback) log_callback(user_data, "Recovered from missing TreePop() in '%s'\n", window->Name);
1027510293
TreePop();
1027610294
}
1027710295
while (g.GroupStack.Size > stack_sizes->SizeOfGroupStack) //-V1044
1027810296
{
10279-
if (log_callback) log_callback(user_data, "Recovered from missing EndGroup() in '%s'", window->Name);
10297+
if (log_callback) log_callback(user_data, "Recovered from missing EndGroup() in '%s'\n", window->Name);
1028010298
EndGroup();
1028110299
}
1028210300
while (window->IDStack.Size > 1)
1028310301
{
10284-
if (log_callback) log_callback(user_data, "Recovered from missing PopID() in '%s'", window->Name);
10302+
if (log_callback) log_callback(user_data, "Recovered from missing PopID() in '%s'\n", window->Name);
1028510303
PopID();
1028610304
}
1028710305
while (g.DisabledStackSize > stack_sizes->SizeOfDisabledStack) //-V1044
1028810306
{
10289-
if (log_callback) log_callback(user_data, "Recovered from missing EndDisabled() in '%s'", window->Name);
10307+
if (log_callback) log_callback(user_data, "Recovered from missing EndDisabled() in '%s'\n", window->Name);
1029010308
if (g.CurrentItemFlags & ImGuiItemFlags_Disabled)
1029110309
EndDisabled();
1029210310
else
@@ -10297,27 +10315,27 @@ void ImGui::ErrorCheckEndWindowRecover(ImGuiErrorLogCallback log_callback, vo
1029710315
}
1029810316
while (g.ColorStack.Size > stack_sizes->SizeOfColorStack)
1029910317
{
10300-
if (log_callback) log_callback(user_data, "Recovered from missing PopStyleColor() in '%s' for ImGuiCol_%s", window->Name, GetStyleColorName(g.ColorStack.back().Col));
10318+
if (log_callback) log_callback(user_data, "Recovered from missing PopStyleColor() in '%s' for ImGuiCol_%s\n", window->Name, GetStyleColorName(g.ColorStack.back().Col));
1030110319
PopStyleColor();
1030210320
}
1030310321
while (g.ItemFlagsStack.Size > stack_sizes->SizeOfItemFlagsStack) //-V1044
1030410322
{
10305-
if (log_callback) log_callback(user_data, "Recovered from missing PopItemFlag() in '%s'", window->Name);
10323+
if (log_callback) log_callback(user_data, "Recovered from missing PopItemFlag() in '%s'\n", window->Name);
1030610324
PopItemFlag();
1030710325
}
1030810326
while (g.StyleVarStack.Size > stack_sizes->SizeOfStyleVarStack) //-V1044
1030910327
{
10310-
if (log_callback) log_callback(user_data, "Recovered from missing PopStyleVar() in '%s'", window->Name);
10328+
if (log_callback) log_callback(user_data, "Recovered from missing PopStyleVar() in '%s'\n", window->Name);
1031110329
PopStyleVar();
1031210330
}
1031310331
while (g.FontStack.Size > stack_sizes->SizeOfFontStack) //-V1044
1031410332
{
10315-
if (log_callback) log_callback(user_data, "Recovered from missing PopFont() in '%s'", window->Name);
10333+
if (log_callback) log_callback(user_data, "Recovered from missing PopFont() in '%s'\n", window->Name);
1031610334
PopFont();
1031710335
}
1031810336
while (g.FocusScopeStack.Size > stack_sizes->SizeOfFocusScopeStack + 1) //-V1044
1031910337
{
10320-
if (log_callback) log_callback(user_data, "Recovered from missing PopFocusScope() in '%s'", window->Name);
10338+
if (log_callback) log_callback(user_data, "Recovered from missing PopFocusScope() in '%s'\n", window->Name);
1032110339
PopFocusScope();
1032210340
}
1032310341
}

imgui_internal.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,7 @@ struct ImGuiTreeNodeStackData
12591259
ImRect NavRect; // Used for nav landing
12601260
};
12611261

1262+
// sizeof() = 18
12621263
struct IMGUI_API ImGuiStackSizes
12631264
{
12641265
short SizeOfIDStack;
@@ -3606,11 +3607,14 @@ namespace ImGui
36063607
IMGUI_API void GcCompactTransientWindowBuffers(ImGuiWindow* window);
36073608
IMGUI_API void GcAwakeTransientWindowBuffers(ImGuiWindow* window);
36083609

3609-
// Debug Tools
3610-
IMGUI_API void DebugAllocHook(ImGuiDebugAllocInfo* info, int frame_count, void* ptr, size_t size); // size >= 0 : alloc, size = -1 : free
3610+
// Error Checking, State Recovery
3611+
IMGUI_API void ErrorLogCallbackToDebugLog(void* user_data, const char* fmt, ...);
36113612
IMGUI_API void ErrorCheckEndFrameRecover(ImGuiErrorLogCallback log_callback, void* user_data = NULL);
36123613
IMGUI_API void ErrorCheckEndWindowRecover(ImGuiErrorLogCallback log_callback, void* user_data = NULL);
36133614
IMGUI_API void ErrorCheckUsingSetCursorPosToExtendParentBoundaries();
3615+
3616+
// Debug Tools
3617+
IMGUI_API void DebugAllocHook(ImGuiDebugAllocInfo* info, int frame_count, void* ptr, size_t size); // size >= 0 : alloc, size = -1 : free
36143618
IMGUI_API void DebugDrawCursorPos(ImU32 col = IM_COL32(255, 0, 0, 255));
36153619
IMGUI_API void DebugDrawLineExtents(ImU32 col = IM_COL32(255, 0, 0, 255));
36163620
IMGUI_API void DebugDrawItemRect(ImU32 col = IM_COL32(255, 0, 0, 255));

0 commit comments

Comments
 (0)