diff --git a/examples/imgui_impl_vulkan_with_textures.cpp b/examples/imgui_impl_vulkan_with_textures.cpp index da5b4d2e..ca5a1100 100644 --- a/examples/imgui_impl_vulkan_with_textures.cpp +++ b/examples/imgui_impl_vulkan_with_textures.cpp @@ -432,8 +432,9 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm VkRect2D scissor; scissor.offset.x = (int32_t)(clip_rect.x); scissor.offset.y = (int32_t)(clip_rect.y); - scissor.extent.width = (uint32_t)(clip_rect.z - clip_rect.x); - scissor.extent.height = (uint32_t)(clip_rect.w - clip_rect.y); + // NOTE(Yan): sometimes x > z which is invalid, hence the abs + scissor.extent.width = (uint32_t)(glm::abs(clip_rect.z - clip_rect.x)); + scissor.extent.height = (uint32_t)(glm::abs(clip_rect.w - clip_rect.y)); vkCmdSetScissor(command_buffer, 0, 1, &scissor); // Bind descriptorset with font or user texture diff --git a/imgui_draw.cpp b/imgui_draw.cpp index b6c51c4e..fcedfe59 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -437,7 +437,12 @@ void ImDrawList::AddDrawCmd() draw_cmd.VtxOffset = _CmdHeader.VtxOffset; draw_cmd.IdxOffset = IdxBuffer.Size; - IM_ASSERT(draw_cmd.ClipRect.x <= draw_cmd.ClipRect.z && draw_cmd.ClipRect.y <= draw_cmd.ClipRect.w); + // NOTE(Yan): Not sure why this happens but sometimes x > z which causes a crash in vkCmdSetScissor later on + // IM_ASSERT(draw_cmd.ClipRect.x <= draw_cmd.ClipRect.z && draw_cmd.ClipRect.y <= draw_cmd.ClipRect.w); + if (draw_cmd.ClipRect.x > draw_cmd.ClipRect.z) + draw_cmd.ClipRect.z = draw_cmd.ClipRect.x + 1; + if (draw_cmd.ClipRect.y > draw_cmd.ClipRect.y) + draw_cmd.ClipRect.w = draw_cmd.ClipRect.w + 1; CmdBuffer.push_back(draw_cmd); }