From 2efaa9a86f5d0164068ce7150b16b977d9c954e0 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 30 Jan 2016 17:01:10 +0100 Subject: [PATCH] ImDrawList: fixed index overflow check broken by AddText(). Added extra assert. (#514) --- imgui.cpp | 3 ++- imgui_draw.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 8ce256c9..35c3ef8d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2289,7 +2289,8 @@ static void AddDrawListToRenderList(ImVector& out_render_list, ImDr // If this assert triggers because you are drawing lots of stuff manually, A) workaround by calling BeginChild()/EndChild() to put your draw commands in multiple draw lists, B) #define ImDrawIdx to a 'unsigned int' in imconfig.h and render accordingly. const unsigned long long int max_vtx_idx = (unsigned long long int)1L << (sizeof(ImDrawIdx)*8); (void)max_vtx_idx; - IM_ASSERT((unsigned long long int)draw_list->_VtxCurrentIdx <= max_vtx_idx); // Too many vertices in same ImDrawList + IM_ASSERT((int)draw_list->_VtxCurrentIdx == draw_list->VtxBuffer.Size); // Sanity check. Bug or mismatch between PrimReserve() calls and incrementing _VtxCurrentIdx, _VtxWritePtr etc. + IM_ASSERT((unsigned long long int)draw_list->_VtxCurrentIdx <= max_vtx_idx); // Too many vertices in same ImDrawList. See comment above. GImGui->IO.MetricsRenderVertices += draw_list->VtxBuffer.Size; GImGui->IO.MetricsRenderIndices += draw_list->IdxBuffer.Size; diff --git a/imgui_draw.cpp b/imgui_draw.cpp index ea521be2..9fbda0c6 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -903,7 +903,7 @@ void ImDrawList::AddText(const ImFont* font, float font_size, const ImVec2& pos, CmdBuffer.back().ElemCount -= idx_unused; _VtxWritePtr -= vtx_unused; _IdxWritePtr -= idx_unused; - _VtxCurrentIdx = (ImDrawIdx)VtxBuffer.Size; + _VtxCurrentIdx = (unsigned int)VtxBuffer.Size; } // This is one of the few function breaking the encapsulation of ImDrawLst, but it is just so useful.