From 42c98c5eea852ef134df043f4cc525810c9076ee Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 30 May 2019 18:47:46 +0200 Subject: [PATCH] ImDrawList: Fix broken channel splitting (broken by d1e8b69) (#2591) --- imgui_draw.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 442c0e18..e4b906ff 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -568,7 +568,10 @@ void ImDrawList::ChannelsMerge() if (CmdBuffer.Size && CmdBuffer.back().ElemCount == 0) CmdBuffer.pop_back(); - int new_cmd_buffer_count = 0, new_idx_buffer_count = 0; + // Calculate our final buffer sizes. Also fix the incorrect IdxOffset values in each command. + int new_cmd_buffer_count = 0; + int new_idx_buffer_count = 0; + int idx_offset = CmdBuffer.back().IdxOffset + CmdBuffer.back().ElemCount; for (int i = 1; i < _ChannelsCount; i++) { ImDrawChannel& ch = _Channels[i]; @@ -576,10 +579,16 @@ void ImDrawList::ChannelsMerge() ch.CmdBuffer.pop_back(); new_cmd_buffer_count += ch.CmdBuffer.Size; new_idx_buffer_count += ch.IdxBuffer.Size; + for (int cmd_n = 0; cmd_n < ch.CmdBuffer.Size; cmd_n++) + { + ch.CmdBuffer.Data[cmd_n].IdxOffset = idx_offset; + idx_offset += ch.CmdBuffer.Data[cmd_n].ElemCount; + } } CmdBuffer.resize(CmdBuffer.Size + new_cmd_buffer_count); IdxBuffer.resize(IdxBuffer.Size + new_idx_buffer_count); + // Flatten our N channels at the end of the first one. ImDrawCmd* cmd_write = CmdBuffer.Data + CmdBuffer.Size - new_cmd_buffer_count; _IdxWritePtr = IdxBuffer.Data + IdxBuffer.Size - new_idx_buffer_count; for (int i = 1; i < _ChannelsCount; i++)