From 949a9fa2cbab18f6d15bf84d3fad438ddcc502ec Mon Sep 17 00:00:00 2001 From: Chris Savoie Date: Mon, 29 Jul 2019 15:52:30 -0700 Subject: [PATCH] Vulkan: Fix crash when viewports are disabled and memory leak on shutdown. (#2698) --- examples/imgui_impl_vulkan.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/imgui_impl_vulkan.cpp b/examples/imgui_impl_vulkan.cpp index 74d111ea..b9026e92 100644 --- a/examples/imgui_impl_vulkan.cpp +++ b/examples/imgui_impl_vulkan.cpp @@ -850,8 +850,17 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass rend void ImGui_ImplVulkan_Shutdown() { - ImGui_ImplVulkan_ShutdownPlatformInterface(); + // First destroy objects in all viewports ImGui_ImplVulkan_DestroyDeviceObjects(); + + // Manually delete main viewport render data in-case we haven't initialized for viewports + ImGuiViewport* main_viewport = ImGui::GetMainViewport(); + if (ImGuiViewportDataVulkan* data = (ImGuiViewportDataVulkan*)main_viewport->RendererUserData) + IM_DELETE(data); + main_viewport->RendererUserData = NULL; + + // Clean up windows + ImGui_ImplVulkan_ShutdownPlatformInterface(); } void ImGui_ImplVulkan_NewFrame()