From 915b46f1c1e8af3fce02ed6baac74012e98bc603 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 9 Aug 2015 11:05:38 -0600 Subject: [PATCH] Added assert on index overflow (#292) --- imgui.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index feedf58c..290d246e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -486,6 +486,7 @@ #endif #ifdef _MSC_VER +#pragma warning (disable: 4127) // condition expression is constant #pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff) #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen #define snprintf _snprintf @@ -2180,6 +2181,15 @@ static void AddDrawListToRenderList(ImVector& out_render_list, ImDr if (draw_list->CmdBuffer.back().ElemCount == 0) draw_list->CmdBuffer.pop_back(); out_render_list.push_back(draw_list); + + if (sizeof(ImDrawIdx) < 4) + { + // Check that draw_list doesn't use more vertices than indexable (default ImDrawIdx = 2 bytes = 64K vertices) + // If this assert triggers because you are drawing lots of stuff manually, a workaround is to use BeginChild()/EndChild() to put your draw commands in a new draw list + unsigned int max_vtx_idx = (unsigned int)1 << (sizeof(ImDrawIdx)*8); + IM_ASSERT(draw_list->_VtxCurrentIdx <= max_vtx_idx); + } + GImGui->IO.MetricsRenderVertices += draw_list->VtxBuffer.Size; GImGui->IO.MetricsRenderIndices += draw_list->IdxBuffer.Size; }