Skip to content

Commit

Permalink
Error Handling, Debug Log: added IMGUI_DEBUG_LOG_ERROR() with special…
Browse files Browse the repository at this point in the history
… handling. (#5855, #1651, #5654)
  • Loading branch information
ocornut committed Sep 27, 2024
1 parent 26785fd commit 2360061
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 17 additions & 2 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3979,8 +3979,9 @@ ImGuiContext::ImGuiContext(ImFontAtlas* shared_font_atlas)
LogDepthToExpand = LogDepthToExpandDefault = 2;

DebugDrawIdConflictsCount = 0;
DebugLogFlags = ImGuiDebugLogFlags_OutputToTTY;
DebugLogFlags = ImGuiDebugLogFlags_EventError | ImGuiDebugLogFlags_OutputToTTY;
DebugLocateId = 0;
DebugLogSkippedErrors = 0;
DebugLogAutoDisableFlags = ImGuiDebugLogFlags_None;
DebugLogAutoDisableFrames = 0;
DebugLocateFrames = 0;
Expand Down Expand Up @@ -16281,12 +16282,24 @@ static void ShowDebugLogFlag(const char* name, ImGuiDebugLogFlags flags)
ImGuiContext& g = *GImGui;
ImVec2 size(ImGui::GetFrameHeight() + g.Style.ItemInnerSpacing.x + ImGui::CalcTextSize(name).x, ImGui::GetFrameHeight());
SameLineOrWrap(size); // FIXME-LAYOUT: To be done automatically once we rework ItemSize/ItemAdd into ItemLayout.

bool highlight_errors = (flags == ImGuiDebugLogFlags_EventError && g.DebugLogSkippedErrors > 0);
if (highlight_errors)
ImGui::PushStyleColor(ImGuiCol_Text, ImLerp(g.Style.Colors[ImGuiCol_Text], ImVec4(1.0f, 0.0f, 0.0f, 1.0f), 0.30f));
if (ImGui::CheckboxFlags(name, &g.DebugLogFlags, flags) && g.IO.KeyShift && (g.DebugLogFlags & flags) != 0)
{
g.DebugLogAutoDisableFrames = 2;
g.DebugLogAutoDisableFlags |= flags;
}
ImGui::SetItemTooltip("Hold SHIFT when clicking to enable for 2 frames only (useful for spammy log entries)");
if (highlight_errors)
{
ImGui::PopStyleColor();
ImGui::SetItemTooltip("%d past errors skipped.", g.DebugLogSkippedErrors);
}
else
{
ImGui::SetItemTooltip("Hold SHIFT when clicking to enable for 2 frames only (useful for spammy log entries)");
}
}

void ImGui::ShowDebugLogWindow(bool* p_open)
Expand All @@ -16304,6 +16317,7 @@ void ImGui::ShowDebugLogWindow(bool* p_open)
CheckboxFlags("All", &g.DebugLogFlags, all_enable_flags);
SetItemTooltip("(except InputRouting which is spammy)");

ShowDebugLogFlag("Errors", ImGuiDebugLogFlags_EventError);
ShowDebugLogFlag("ActiveId", ImGuiDebugLogFlags_EventActiveId);
ShowDebugLogFlag("Clipper", ImGuiDebugLogFlags_EventClipper);
ShowDebugLogFlag("Focus", ImGuiDebugLogFlags_EventFocus);
Expand All @@ -16317,6 +16331,7 @@ void ImGui::ShowDebugLogWindow(bool* p_open)
{
g.DebugLogBuf.clear();
g.DebugLogIndex.clear();
g.DebugLogSkippedErrors = 0;
}
SameLine();
if (SmallButton("Copy"))
Expand Down
2 changes: 2 additions & 0 deletions imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer
#else
#define IMGUI_DEBUG_LOG(...) ((void)0)
#endif
#define IMGUI_DEBUG_LOG_ERROR(...) do { ImGuiContext& g2 = *GImGui; if (g2.DebugLogFlags & ImGuiDebugLogFlags_EventError) IMGUI_DEBUG_LOG(__VA_ARGS__); else g2.DebugLogSkippedErrors++; } while (0)
#define IMGUI_DEBUG_LOG_ACTIVEID(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventActiveId) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0)
#define IMGUI_DEBUG_LOG_FOCUS(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventFocus) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0)
#define IMGUI_DEBUG_LOG_POPUP(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventPopup) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0)
Expand Down Expand Up @@ -2321,6 +2322,7 @@ struct ImGuiContext
ImGuiDebugLogFlags DebugLogFlags;
ImGuiTextBuffer DebugLogBuf;
ImGuiTextIndex DebugLogIndex;
int DebugLogSkippedErrors;
ImGuiDebugLogFlags DebugLogAutoDisableFlags;
ImU8 DebugLogAutoDisableFrames;
ImU8 DebugLocateFrames; // For DebugLocateItemOnHover(). This is used together with DebugLocateId which is in a hot/cached spot above.
Expand Down

0 comments on commit 2360061

Please sign in to comment.