From efa50f72a70ffea211ff27bbf0f973afc46767ff Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 3 Jan 2022 22:14:19 +0100 Subject: [PATCH] Backends: Metal: Ignore ImDrawCmd where ElemCount == 0. (#4857) --- backends/imgui_impl_metal.mm | 3 +++ docs/CHANGELOG.txt | 2 ++ 2 files changed, 5 insertions(+) diff --git a/backends/imgui_impl_metal.mm b/backends/imgui_impl_metal.mm index 1b1560915a5b..358103f1b8ec 100644 --- a/backends/imgui_impl_metal.mm +++ b/backends/imgui_impl_metal.mm @@ -12,6 +12,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2022-01-03: Metal: Ignore ImDrawCmd where ElemCount == 0 (very rare but can technically be manufactured by user code). // 2021-12-30: Metal: Added Metal C++ support. Enable with '#define IMGUI_IMPL_METAL_CPP' in your imconfig.h file. // 2021-08-24: Metal: Fixed a crash when clipping rect larger than framebuffer is submitted. (#4464) // 2021-05-19: Metal: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement) @@ -552,6 +553,8 @@ - (void)renderDrawData:(ImDrawData *)drawData if (clip_max.y > fb_height) { clip_max.y = (float)fb_height; } if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y) continue; + if (pcmd->ElemCount == 0) // drawIndexedPrimitives() validation doesn't accept this + continue; // Apply scissor/clipping rectangle MTLScissorRect scissorRect = diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 95b5a334d18d..38b71a1eca46 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -54,6 +54,8 @@ Other Changes: It would generally not have noticeable side-effect at runtime but would be detected by runtime checkers. - Backends: Metal: Added Apple Metal C++ API support. (#4824, #4746) [@luigifcruz] Enable with '#define IMGUI_IMPL_METAL_CPP' in your imconfig.h file. +- Backends: Metal: Ignore ImDrawCmd where ElemCount == 0, which are normally not emitted by the library but + can theorically be created by user code manipulating a ImDrawList. (#4857) -----------------------------------------------------------------------