From 65b4553490a24478d7e9d53a2863584559349dff Mon Sep 17 00:00:00 2001 From: TheCherno Date: Sun, 20 Feb 2022 10:43:38 +1100 Subject: [PATCH] Fixed viewport swapchains not getting recreated in some cases --- examples/imgui_impl_vulkan_with_textures.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/examples/imgui_impl_vulkan_with_textures.cpp b/examples/imgui_impl_vulkan_with_textures.cpp index 3ce00f9a..92b144b0 100644 --- a/examples/imgui_impl_vulkan_with_textures.cpp +++ b/examples/imgui_impl_vulkan_with_textures.cpp @@ -1477,7 +1477,20 @@ static void ImGui_ImplVulkan_SwapBuffers(ImGuiViewport* viewport, void*) info.pSwapchains = &wd->Swapchain; info.pImageIndices = &present_index; err = vkQueuePresentKHR(v->Queue, &info); - check_vk_result(err); + //check_vk_result(err); + if (err != VK_SUCCESS || err == VK_SUBOPTIMAL_KHR) + { + if (err == VK_ERROR_OUT_OF_DATE_KHR) + { + // Swap chain is no longer compatible with the surface and needs to be recreated + ImGui_ImplVulkanH_CreateOrResizeWindow(v->Instance, v->PhysicalDevice, v->Device, wd, v->QueueFamily, v->Allocator, (int)viewport->Size.x, (int)viewport->Size.y, v->MinImageCount); + return; + } + else + { + check_vk_result(err); + } + } wd->FrameIndex = (wd->FrameIndex + 1) % wd->ImageCount; // This is for the next vkWaitForFences() wd->SemaphoreIndex = (wd->SemaphoreIndex + 1) % wd->ImageCount; // Now we can use the next set of semaphores