Skip to content

Commit 0ba02a4

Browse files
committed
Debug Tools: added IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS. (ocornut#8651, ocornut#7961, ocornut#7669)
1 parent f39b138 commit 0ba02a4

4 files changed

Lines changed: 36 additions & 0 deletions

File tree

docs/CHANGELOG.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ Other changes:
6161
- Demo: Added "Text -> Font Size" demo section. (#8738) [@Demonese]
6262
- CI: Fixed dllimport/dllexport tests. (#8757) [@AidanSun05]
6363
- CI: Updated to use latest Windows image + VS2022.
64+
- Debug Tools: added IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS to detect
65+
id conflicts _before_ hovering. This is very slow and should only be used
66+
temporarily. (#8651, #7961, #7669)
6467
- Examples: GLFW+OpenGL3, GLFW+WGPU: Emscripten Makefiles uses GLFW port
6568
'contrib.glfw3' which offers better HiDPI support. (#8742) [@pthom]
6669
- Backends: GLFW, SDL2 made ImGui_ImplGLFW_GetContentScaleXXX() and

imconfig.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@
129129
//#define IM_DEBUG_BREAK IM_ASSERT(0)
130130
//#define IM_DEBUG_BREAK __debugbreak()
131131

132+
//---- Debug Tools: Enable highlight ID conflicts _before_ hovering items. When io.ConfigDebugHighlightIdConflicts is set.
133+
// (THIS WILL SLOW DOWN DEAR IMGUI. Only use occasionally and disable after use)
134+
//#define IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS
135+
132136
//---- Debug Tools: Enable slower asserts
133137
//#define IMGUI_DEBUG_PARANOID
134138

imgui.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4263,6 +4263,12 @@ void ImGui::Initialize()
42634263
#ifdef IMGUI_HAS_DOCK
42644264
#endif
42654265

4266+
// Print a debug message when running with debug feature IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS because it is very slow.
4267+
// DO NOT COMMENT OUT THIS MESSAGE. IT IS DESIGNED TO REMIND YOU THAT IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS SHOULD ONLY BE TEMPORARILY ENABLED.
4268+
#ifdef IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS
4269+
DebugLog("IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS is enabled.\nMust disable after use! Otherwise Dear ImGui will run slower.\n");
4270+
#endif
4271+
42664272
// ImDrawList/ImFontAtlas are designed to function without ImGui, and 99% of it works without an ImGui context.
42674273
// But this link allows us to facilitate/handle a few edge cases better.
42684274
ImFontAtlas* atlas = g.IO.Fonts;
@@ -11012,6 +11018,21 @@ bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg, ImGu
1101211018
// Empty identifier are valid and useful in a small amount of cases, but 99.9% of the time you want to use "##something".
1101311019
// READ THE FAQ: https://dearimgui.com/faq
1101411020
IM_ASSERT(id != window->ID && "Cannot have an empty ID at the root of a window. If you need an empty label, use ## and read the FAQ about how the ID Stack works!");
11021+
11022+
// [DEBUG] Highlight all conflicts WITHOUT needing to hover. THIS WILL SLOW DOWN DEAR IMGUI. DON'T KEEP ACTIVATED.
11023+
// This will only work for items submitted with ItemAdd(). Some very rare/odd/unrecommended code patterns are calling ButtonBehavior() without ItemAdd().
11024+
#ifdef IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS
11025+
if ((g.LastItemData.ItemFlags & ImGuiItemFlags_AllowDuplicateId) == 0)
11026+
{
11027+
int* p_alive = g.DebugDrawIdConflictsAliveCount.GetIntRef(id, -1); // Could halve lookups if we knew ImGuiStorage can store 64-bit, or by storing FrameCount as 30-bits + highlight as 2-bits. But the point is that we should not pretend that this is fast.
11028+
int* p_highlight = g.DebugDrawIdConflictsHighlightSet.GetIntRef(id, -1);
11029+
if (*p_alive == g.FrameCount)
11030+
*p_highlight = g.FrameCount;
11031+
*p_alive = g.FrameCount;
11032+
if (*p_highlight >= g.FrameCount - 1)
11033+
window->DrawList->AddRect(bb.Min - ImVec2(1, 1), bb.Max + ImVec2(1, 1), IM_COL32(255, 0, 0, 255), 0.0f, ImDrawFlags_None, 2.0f);
11034+
}
11035+
#endif
1101511036
}
1101611037
//if (g.IO.KeyAlt) window->DrawList->AddRect(bb.Min, bb.Max, IM_COL32(255,255,0,120)); // [DEBUG]
1101711038
//if ((g.LastItemData.ItemFlags & ImGuiItemFlags_NoNav) == 0)
@@ -16126,6 +16147,10 @@ void ImGui::ShowMetricsWindow(bool* p_open)
1612616147
}
1612716148
};
1612816149

16150+
#ifdef IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS
16151+
TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS is enabled.\nMust disable after use! Otherwise Dear ImGui will run slower.\n");
16152+
#endif
16153+
1612916154
// Tools
1613016155
if (TreeNode("Tools"))
1613116156
{

imgui_internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,6 +2495,10 @@ struct ImGuiContext
24952495
ImGuiMetricsConfig DebugMetricsConfig;
24962496
ImGuiIDStackTool DebugIDStackTool;
24972497
ImGuiDebugAllocInfo DebugAllocInfo;
2498+
#if defined(IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS) && !defined(IMGUI_DISABLE_DEBUG_TOOLS)
2499+
ImGuiStorage DebugDrawIdConflictsAliveCount;
2500+
ImGuiStorage DebugDrawIdConflictsHighlightSet;
2501+
#endif
24982502

24992503
// Misc
25002504
float FramerateSecPerFrame[60]; // Calculate estimate of framerate for user over the last 60 frames..

0 commit comments

Comments
 (0)