From 8ec05fc0342e81a023fba85b8b19e7ad6104ff46 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 23 Sep 2020 14:22:41 +0200 Subject: [PATCH] Tables: Fixed holding on table pointers accross resize/invalidation of the pool buffer. --- imgui.cpp | 3 ++- imgui_internal.h | 2 +- imgui_tables.cpp | 10 ++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index e12cbae1..823fe725 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2931,7 +2931,7 @@ static void SetCurrentWindow(ImGuiWindow* window) { ImGuiContext& g = *GImGui; g.CurrentWindow = window; - g.CurrentTable = window ? window->DC.CurrentTable : NULL; + g.CurrentTable = window && window->DC.CurrentTableIdx != -1 ? g.Tables.GetByIndex(window->DC.CurrentTableIdx) : NULL; if (window) g.FontSize = g.DrawListSharedData.FontSize = window->CalcFontSize(); } @@ -5623,6 +5623,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->ClipRect = ImVec4(-FLT_MAX, -FLT_MAX, +FLT_MAX, +FLT_MAX); window->IDStack.resize(1); window->DrawList->_ResetForNewFrame(); + window->DC.CurrentTableIdx = -1; // Restore buffer capacity when woken from a compacted state, to avoid if (window->MemoryCompacted) diff --git a/imgui_internal.h b/imgui_internal.h index 261f1be1..054252f2 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1657,7 +1657,7 @@ struct IMGUI_API ImGuiWindowTempData ImVector ChildWindows; ImGuiStorage* StateStorage; // Current persistent per-window storage (store e.g. tree node open/close state) ImGuiOldColumns* CurrentColumns; // Current columns set - ImGuiTable* CurrentTable; // Current table set + int CurrentTableIdx; // Current table index (into g.Tables) ImGuiLayoutType LayoutType; ImGuiLayoutType ParentLayoutType; // Layout type of parent window at the time of Begin() int FocusCounterRegular; // (Legacy Focus/Tabbing system) Sequential counter, start at -1 and increase as assigned via FocusableItemRegister() (FIXME-NAV: Needs redesign) diff --git a/imgui_tables.cpp b/imgui_tables.cpp index efa41dd9..51249f4b 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -305,11 +305,12 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG table->BorderX2 = table->InnerClipRect.Max.x;// +((table->Flags & ImGuiTableFlags_BordersOuter) ? 0.0f : +1.0f); // Make table current - g.CurrentTableStack.push_back(ImGuiPtrOrIndex(g.Tables.GetIndex(table))); + const int table_idx = g.Tables.GetIndex(table); + g.CurrentTableStack.push_back(ImGuiPtrOrIndex(table_idx)); g.CurrentTable = table; - outer_window->DC.CurrentTable = table; + outer_window->DC.CurrentTableIdx = table_idx; if (inner_window != outer_window) // So EndChild() within the inner window can restore the table properly. - inner_window->DC.CurrentTable = table; + inner_window->DC.CurrentTableIdx = table_idx; if ((table_last_flags & ImGuiTableFlags_Reorderable) && !(flags & ImGuiTableFlags_Reorderable)) table->IsResetDisplayOrderRequest = true; @@ -1116,7 +1117,8 @@ void ImGui::EndTable() IM_ASSERT(g.CurrentWindow == outer_window); IM_ASSERT(g.CurrentTable == table); g.CurrentTableStack.pop_back(); - outer_window->DC.CurrentTable = g.CurrentTable = g.CurrentTableStack.Size ? g.Tables.GetByIndex(g.CurrentTableStack.back().Index) : NULL; + g.CurrentTable = g.CurrentTableStack.Size ? g.Tables.GetByIndex(g.CurrentTableStack.back().Index) : NULL; + outer_window->DC.CurrentTableIdx = g.CurrentTable ? g.Tables.GetIndex(g.CurrentTable) : -1; } // FIXME-TABLE: This is a mess, need to redesign how we render borders.