From eaef343d01a485816761769067fdb759d48cef1a Mon Sep 17 00:00:00 2001 From: Dale Kim Date: Wed, 13 Aug 2014 13:09:11 -0500 Subject: [PATCH] Fix unchecked access to command buffer. In the example application, clicking on the Combo list under Widgets will cause an assert. This commit checks if the command buffer is empty before attempting to access it. --- imgui.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 96399b2a1..9501fa534 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4660,10 +4660,14 @@ void ImDrawList::ReserveVertices(unsigned int vtx_count) { if (vtx_count > 0) { - ImDrawCmd& draw_cmd = commands.back(); - draw_cmd.vtx_count += vtx_count; - vtx_buffer.resize(vtx_buffer.size() + vtx_count); - vtx_write = &vtx_buffer[vtx_buffer.size() - vtx_count]; + if (!commands.empty()) + { + ImDrawCmd& draw_cmd = commands.back(); + draw_cmd.vtx_count += vtx_count; + } + + vtx_buffer.resize(vtx_buffer.size() + vtx_count); + vtx_write = &vtx_buffer[vtx_buffer.size() - vtx_count]; } }