Skip to content

Commit 9cf9d2b

Browse files
committed
Debug Tools: ID Stack Tool: fixed a crash when using PushOverrideID(0) during a query. (#8937, #4631)
1 parent 7e473d3 commit 9cf9d2b

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

‎docs/CHANGELOG.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ Other Changes:
103103
is now skipped. (#8904, #4631)
104104
- Debug Tools: ID Stack Tool: added option to hex-encode non-ASCII characters in
105105
output path. (#8904, #4631)
106+
- Debug Tools: ID Stack Tool: fixed a crash when using PushOverrideID(0) during
107+
a query. (#8937, #4631)
106108
- Debug Tools: Fixed assertion failure when opening a combo box while using
107109
io.ConfigDebugBeginReturnValueOnce/ConfigDebugBeginReturnValueLoop. (#8931) [@harrymander]
108110
- Demo: tweaked ShowFontSelector() and ShowStyleSelector() to update selection

‎imgui.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17662,6 +17662,7 @@ void ImGui::UpdateDebugToolStackQueries()
1766217662

1766317663
// Clear hook when id stack tool is not visible
1766417664
g.DebugHookIdInfoId = 0;
17665+
tool->QueryHookActive = false;
1766517666
if (g.FrameCount != tool->LastActiveFrame + 1)
1766617667
return;
1766717668

@@ -17687,11 +17688,15 @@ void ImGui::UpdateDebugToolStackQueries()
1768717688
// Update hook
1768817689
stack_level = tool->StackLevel;
1768917690
if (stack_level == -1)
17691+
{
1769017692
g.DebugHookIdInfoId = query_main_id;
17693+
tool->QueryHookActive = true;
17694+
}
1769117695
else if (stack_level >= 0 && stack_level < tool->Results.Size)
1769217696
{
1769317697
g.DebugHookIdInfoId = tool->Results[stack_level].ID;
1769417698
tool->Results[stack_level].QueryFrameCount++;
17699+
tool->QueryHookActive = true;
1769517700
}
1769617701
}
1769717702

@@ -17701,11 +17706,17 @@ void ImGui::DebugHookIdInfo(ImGuiID id, ImGuiDataType data_type, const void* dat
1770117706
ImGuiContext& g = *GImGui;
1770217707
ImGuiWindow* window = g.CurrentWindow;
1770317708
ImGuiIDStackTool* tool = &g.DebugIDStackTool;
17709+
if (tool->QueryHookActive == false)
17710+
{
17711+
IM_ASSERT(id == 0);
17712+
return;
17713+
}
1770417714

1770517715
// Step 0: stack query
1770617716
// This assumes that the ID was computed with the current ID stack, which tends to be the case for our widget.
1770717717
if (tool->StackLevel == -1)
1770817718
{
17719+
IM_ASSERT(tool->Results.Size == 0);
1770917720
tool->StackLevel++;
1771017721
tool->Results.resize(window->IDStack.Size + 1, ImGuiStackLevelInfo());
1771117722
for (int n = 0; n < window->IDStack.Size + 1; n++)

‎imgui_internal.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,6 +2128,7 @@ struct ImGuiIDStackTool
21282128
int StackLevel; // -1: query stack and resize Results, >= 0: individual stack level
21292129
ImGuiID QueryMainId; // ID to query details for
21302130
ImVector<ImGuiStackLevelInfo> Results;
2131+
bool QueryHookActive; // Used to disambiguate the case where DebugHookIdInfoId == 0 which is valid.
21312132
bool OptHexEncodeNonAsciiChars;
21322133
bool OptCopyToClipboardOnCtrlC;
21332134
float CopyToClipboardLastTime;

0 commit comments

Comments
 (0)
⌂ 换网址