ImDrawList: fixed index overflow check broken by AddText(). Added extra assert. (#514)
diff --git a/imgui.cpp b/imgui.cpp
index 8ce256c..35c3ef8 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -2289,7 +2289,8 @@
// 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 ea521be..9fbda0c 100644
--- a/imgui_draw.cpp
+++ b/imgui_draw.cpp
@@ -903,7 +903,7 @@
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.