From 6f41d13c7a93cf65aca4afe9bf24b610740c3d5a Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 20 Jul 2026 16:57:17 +0200 Subject: [PATCH] DrawData: added FrameCount field to facilitate debugging multi-threading issues. (#8597, #9136) --- imgui.cpp | 7 ++++--- imgui.h | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 2e97af26b..741d6b2a7 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5954,7 +5954,7 @@ static void FlattenDrawDataIntoSingleLayer(ImDrawDataBuilder* builder) static void InitViewportDrawData(ImGuiViewportP* viewport) { - ImGuiIO& io = ImGui::GetIO(); + ImGuiContext& g = *GImGui; ImDrawData* draw_data = &viewport->DrawDataP; viewport->DrawDataBuilder.Layers[0] = &draw_data->CmdLists; @@ -5963,12 +5963,13 @@ static void InitViewportDrawData(ImGuiViewportP* viewport) viewport->DrawDataBuilder.Layers[1]->resize(0); draw_data->Valid = true; + draw_data->FrameCount = g.FrameCount; draw_data->TotalVtxCount = draw_data->TotalIdxCount = 0; draw_data->DisplayPos = viewport->Pos; draw_data->DisplaySize = viewport->Size; - draw_data->FramebufferScale = io.DisplayFramebufferScale; + draw_data->FramebufferScale = g.IO.DisplayFramebufferScale; draw_data->OwnerViewport = viewport; - draw_data->Textures = &ImGui::GetPlatformIO().Textures; + draw_data->Textures = &g.PlatformIO.Textures; #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS draw_data->CmdListsCount = 0; #endif diff --git a/imgui.h b/imgui.h index d219d5a6d..155f1093b 100644 --- a/imgui.h +++ b/imgui.h @@ -3493,6 +3493,7 @@ struct ImDrawList struct ImDrawData { bool Valid; // Only valid after Render() is called and before the next NewFrame() is called. + int FrameCount; // Frame counter of the emitter context. For debugging purpose. int TotalIdxCount; // For convenience, sum of all ImDrawList's IdxBuffer.Size int TotalVtxCount; // For convenience, sum of all ImDrawList's VtxBuffer.Size ImVector CmdLists; // Array of ImDrawList* to render. The ImDrawLists are owned by ImGuiContext and only pointed to from here.