Skip to content

Commit 3fdb8e3

Browse files
committed
Canvas: Ensure canvas draw commands are separated from other ImGui draw commands (#205, #250)
1 parent 4bd3012 commit 3fdb8e3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

docs/CHANGELOG.txt

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ v0.9.2 (WIP):
4141

4242
BUGFIX: Editor: Clean long to int implicit cast warning in crude_json
4343

44+
BUGFIX: Canvas: Ensure canvas draw commands are separated from other ImGui draw commands (#205, #250)
45+
4446

4547
v0.9.1 (2022-08-27):
4648

imgui_canvas.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ struct VtxCurrentOffsetRef
6868
}
6969
};
7070

71+
static void SentinelDrawCallback(const ImDrawList* parent_list, const ImDrawCmd* cmd)
72+
{
73+
// This is a sentinel draw callback, it's only purpose is to mark draw list command.
74+
IM_ASSERT(false && "This draw callback should never be called.");
75+
}
76+
7177
} // namespace ImCanvasDetails
7278

7379
// Returns a reference to _FringeScale extension to ImDrawList
@@ -429,7 +435,7 @@ void ImGuiEx::Canvas::EnterLocalSpace()
429435
//
430436
// More investigation is needed. To get to the bottom of this.
431437
if ((!m_DrawList->CmdBuffer.empty() && m_DrawList->CmdBuffer.back().ElemCount > 0) || m_DrawList->_Splitter._Count > 1)
432-
m_DrawList->AddDrawCmd();
438+
m_DrawList->AddCallback(&ImCanvasDetails::SentinelDrawCallback, nullptr);
433439

434440
# if IMGUI_EX_CANVAS_DEFERED()
435441
m_Ranges.resize(m_Ranges.Size + 1);
@@ -547,6 +553,10 @@ void ImGuiEx::Canvas::LeaveLocalSpace()
547553
}
548554
}
549555

556+
// Remove sentinel draw command if present
557+
if (m_DrawListCommadBufferSize > 0 && m_DrawList->CmdBuffer.size() >= m_DrawListCommadBufferSize && m_DrawList->CmdBuffer[m_DrawListCommadBufferSize - 1].UserCallback == &ImCanvasDetails::SentinelDrawCallback)
558+
m_DrawList->CmdBuffer.erase(m_DrawList->CmdBuffer.Data + m_DrawListCommadBufferSize - 1);
559+
550560
auto& fringeScale = ImFringeScaleRef(m_DrawList);
551561
fringeScale = m_LastFringeScale;
552562

0 commit comments

Comments
 (0)