From 199a44e31e20f7620fc1d67b69107b3c2a8eda8a Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 26 Sep 2024 17:51:46 +0200 Subject: [PATCH] Error Handling: fixed not rewinding to recorded tree and id stack size (#1651) --- imgui.cpp | 5 +++-- imgui_internal.h | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 306a730ce..5379248c8 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -10465,6 +10465,7 @@ void ImGui::ErrorRecoveryStoreState(ImGuiErrorRecoveryState* state_out) ImGuiContext& g = *GImGui; state_out->SizeOfWindowStack = (short)g.CurrentWindowStack.Size; state_out->SizeOfIDStack = (short)g.CurrentWindow->IDStack.Size; + state_out->SizeOfTreeStack = (short)g.CurrentWindow->DC.TreeDepth; // NOT g.TreeNodeStack.Size which is a partial stack! state_out->SizeOfColorStack = (short)g.ColorStack.Size; state_out->SizeOfStyleVarStack = (short)g.StyleVarStack.Size; state_out->SizeOfFontStack = (short)g.FontStack.Size; @@ -10531,7 +10532,7 @@ void ImGui::ErrorRecoveryTryToRecoverWindowState(const ImGuiErrorRecoveryStat IM_ASSERT_USER_ERROR(0, "Missing EndMultiSelect()"); EndMultiSelect(); } - while (window->DC.TreeDepth > 0) + while (window->DC.TreeDepth > state_in->SizeOfTreeStack) //-V1044 { IM_ASSERT_USER_ERROR(0, "Missing TreePop()"); TreePop(); @@ -10542,7 +10543,7 @@ void ImGui::ErrorRecoveryTryToRecoverWindowState(const ImGuiErrorRecoveryStat EndGroup(); } IM_ASSERT(g.GroupStack.Size == state_in->SizeOfGroupStack); - while (window->IDStack.Size > 1) + while (window->IDStack.Size > state_in->SizeOfIDStack) //-V1044 { IM_ASSERT_USER_ERROR(0, "Missing PopID()"); PopID(); diff --git a/imgui_internal.h b/imgui_internal.h index 52664a1c5..cb9071478 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1258,6 +1258,7 @@ struct IMGUI_API ImGuiErrorRecoveryState { short SizeOfWindowStack; short SizeOfIDStack; + short SizeOfTreeStack; short SizeOfColorStack; short SizeOfStyleVarStack; short SizeOfFontStack;