Debug Tools: added IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS. (#8651, #7961, #7669)

This commit is contained in:
ocornut
2025-07-09 18:43:25 +02:00
parent f39b138487
commit 0ba02a4ed6
4 changed files with 36 additions and 0 deletions

View File

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

View File

@@ -129,6 +129,10 @@
//#define IM_DEBUG_BREAK IM_ASSERT(0)
//#define IM_DEBUG_BREAK __debugbreak()
//---- Debug Tools: Enable highlight ID conflicts _before_ hovering items. When io.ConfigDebugHighlightIdConflicts is set.
// (THIS WILL SLOW DOWN DEAR IMGUI. Only use occasionally and disable after use)
//#define IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS
//---- Debug Tools: Enable slower asserts
//#define IMGUI_DEBUG_PARANOID

View File

@@ -4263,6 +4263,12 @@ void ImGui::Initialize()
#ifdef IMGUI_HAS_DOCK
#endif
// Print a debug message when running with debug feature IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS because it is very slow.
// DO NOT COMMENT OUT THIS MESSAGE. IT IS DESIGNED TO REMIND YOU THAT IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS SHOULD ONLY BE TEMPORARILY ENABLED.
#ifdef IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS
DebugLog("IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS is enabled.\nMust disable after use! Otherwise Dear ImGui will run slower.\n");
#endif
// ImDrawList/ImFontAtlas are designed to function without ImGui, and 99% of it works without an ImGui context.
// But this link allows us to facilitate/handle a few edge cases better.
ImFontAtlas* atlas = g.IO.Fonts;
@@ -11012,6 +11018,21 @@ bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg, ImGu
// Empty identifier are valid and useful in a small amount of cases, but 99.9% of the time you want to use "##something".
// READ THE FAQ: https://dearimgui.com/faq
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!");
// [DEBUG] Highlight all conflicts WITHOUT needing to hover. THIS WILL SLOW DOWN DEAR IMGUI. DON'T KEEP ACTIVATED.
// This will only work for items submitted with ItemAdd(). Some very rare/odd/unrecommended code patterns are calling ButtonBehavior() without ItemAdd().
#ifdef IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS
if ((g.LastItemData.ItemFlags & ImGuiItemFlags_AllowDuplicateId) == 0)
{
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.
int* p_highlight = g.DebugDrawIdConflictsHighlightSet.GetIntRef(id, -1);
if (*p_alive == g.FrameCount)
*p_highlight = g.FrameCount;
*p_alive = g.FrameCount;
if (*p_highlight >= g.FrameCount - 1)
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);
}
#endif
}
//if (g.IO.KeyAlt) window->DrawList->AddRect(bb.Min, bb.Max, IM_COL32(255,255,0,120)); // [DEBUG]
//if ((g.LastItemData.ItemFlags & ImGuiItemFlags_NoNav) == 0)
@@ -16126,6 +16147,10 @@ void ImGui::ShowMetricsWindow(bool* p_open)
}
};
#ifdef IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS
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");
#endif
// Tools
if (TreeNode("Tools"))
{

View File

@@ -2495,6 +2495,10 @@ struct ImGuiContext
ImGuiMetricsConfig DebugMetricsConfig;
ImGuiIDStackTool DebugIDStackTool;
ImGuiDebugAllocInfo DebugAllocInfo;
#if defined(IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS) && !defined(IMGUI_DISABLE_DEBUG_TOOLS)
ImGuiStorage DebugDrawIdConflictsAliveCount;
ImGuiStorage DebugDrawIdConflictsHighlightSet;
#endif
// Misc
float FramerateSecPerFrame[60]; // Calculate estimate of framerate for user over the last 60 frames..