From d9e60d29e1cab8c0b5370f92ce73b992ac77b3f1 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 17 Feb 2022 11:09:06 +0100 Subject: [PATCH] Clipper: Fixed a regresssion when not calling End() + calling End() twice as well. (#4822) --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 14 +++++++------- imgui.h | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 05c3c4c8..47d3c67c 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -39,6 +39,8 @@ Breaking changes: Other Changes: +- Clipper: Fixed a regression in 1.86 when not calling clipper.End() and late destructing the + clipper instance. High-level languages (Lua,Rust etc.) would typically be affected. (#4822) - Inputs: Fixed IsMouseClicked() repeat mode rate being half of keyboard repeat rate. - Stack Tool: Added option to copy item path to clipboard. (#4631) - Misc: Added constexpr to ImVec2/ImVec4 inline constructors. (#4995) [@Myriachan] diff --git a/imgui.cpp b/imgui.cpp index f7c8b613..d7f09ddf 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2565,15 +2565,14 @@ void ImGuiListClipper::Begin(int items_count, float items_height) void ImGuiListClipper::End() { - // In theory here we should assert that we are already at the right position, but it seems saner to just seek at the end and not assert/crash the user. ImGuiContext& g = *GImGui; - if (ItemsCount >= 0 && ItemsCount < INT_MAX && DisplayStart >= 0) - ImGuiListClipper_SeekCursorForItem(this, ItemsCount); - ItemsCount = -1; - - // Restore temporary buffer and fix back pointers which may be invalidated when nesting if (ImGuiListClipperData* data = (ImGuiListClipperData*)TempData) { + // In theory here we should assert that we are already at the right position, but it seems saner to just seek at the end and not assert/crash the user. + if (ItemsCount >= 0 && ItemsCount < INT_MAX && DisplayStart >= 0) + ImGuiListClipper_SeekCursorForItem(this, ItemsCount); + + // Restore temporary buffer and fix back pointers which may be invalidated when nesting IM_ASSERT(data->ListClipper == this); data->StepNo = data->Ranges.Size; if (--g.ClipperTempDataStacked > 0) @@ -2583,6 +2582,7 @@ void ImGuiListClipper::End() } TempData = NULL; } + ItemsCount = -1; } void ImGuiListClipper::ForceDisplayRangeByIndices(int item_min, int item_max) @@ -2715,8 +2715,8 @@ bool ImGuiListClipper::Step() // Advance the cursor to the end of the list and then returns 'false' to end the loop. if (ItemsCount < INT_MAX) ImGuiListClipper_SeekCursorForItem(this, ItemsCount); - ItemsCount = -1; + End(); return false; } diff --git a/imgui.h b/imgui.h index 771f3547..e38dfd64 100644 --- a/imgui.h +++ b/imgui.h @@ -65,7 +65,7 @@ Index of this file: // Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) #define IMGUI_VERSION "1.88 WIP" -#define IMGUI_VERSION_NUM 18705 +#define IMGUI_VERSION_NUM 18706 #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) #define IMGUI_HAS_TABLE