From 065c6c0d0a2386ba31cdd92f82f291fdae2bf8bb Mon Sep 17 00:00:00 2001 From: Mikko Mononen Date: Tue, 2 Jun 2026 12:27:39 +0300 Subject: [PATCH] DrawList: fixed indices when AllowVtxOffset is on - fix shape closing indices for AddPolyline and _AddRectTinyRounding --- imgui_draw.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 33013c6a2..fbbcff63b 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1177,8 +1177,8 @@ void ImDrawList::_AddPolyline(const ImVec2* points, ImVec2* normals, float* sqr_ else { // Connect the path. - start_vtx_ptr[0] = VtxBuffer.Data[base_idx+0]; - start_vtx_ptr[1] = VtxBuffer.Data[base_idx+1]; + start_vtx_ptr[0] = VtxBuffer.Data[_CmdHeader.VtxOffset + base_idx+0]; + start_vtx_ptr[1] = VtxBuffer.Data[_CmdHeader.VtxOffset + base_idx+1]; } // Restore unused memory @@ -2500,6 +2500,7 @@ void ImDrawList::_AddRectBaked(const ImVec2& p_min, const ImVec2& p_max, ImU32 c const int idx_used = (int)(_IdxWritePtr - start_idx_ptr); const int vtx_used = (int)(_VtxWritePtr - start_vtx_ptr); + IM_ASSERT_PARANOID(idx_used <= idx_allocated && vtx_used <= vtx_allocated); if (idx_used < idx_allocated || vtx_used < vtx_allocated) PrimUnreserve(idx_allocated - idx_used, vtx_allocated - vtx_used); } @@ -2613,13 +2614,13 @@ void ImDrawList::_AddRectTinyRounding(const ImVec2& p_min, const ImVec2& p_max, } // Close - start_vtx_ptr[0] = VtxBuffer.Data[base_idx + 0]; - start_vtx_ptr[1] = VtxBuffer.Data[base_idx + 1]; - start_vtx_ptr[2] = VtxBuffer.Data[base_idx + 2]; + start_vtx_ptr[0] = VtxBuffer.Data[_CmdHeader.VtxOffset + base_idx + 0]; + start_vtx_ptr[1] = VtxBuffer.Data[_CmdHeader.VtxOffset + base_idx + 1]; + start_vtx_ptr[2] = VtxBuffer.Data[_CmdHeader.VtxOffset + base_idx + 2]; const int idx_used = (int)(_IdxWritePtr - start_idx_ptr); const int vtx_used = (int)(_VtxWritePtr - start_vtx_ptr); - IM_ASSERT(idx_used <= idx_count && vtx_used <= vtx_count); + IM_ASSERT_PARANOID(idx_used <= idx_count && vtx_used <= vtx_count); if (idx_used < idx_count || vtx_used < vtx_count) PrimUnreserve(idx_count - idx_used, vtx_count - vtx_used);