From 5e552c0fea236e229c3a534a9481f2f2f458f8de Mon Sep 17 00:00:00 2001 From: saschawillems Date: Sat, 30 Jun 2018 21:55:29 +0200 Subject: [PATCH] Recreate swap chain (and resources) if it's out of date Refs #493 --- base/vulkanexamplebase.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index 4ae9f396..0a66e133 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -656,7 +656,16 @@ void VulkanExampleBase::submitFrame() submitInfo.pSignalSemaphores = &semaphores.renderComplete; } - VK_CHECK_RESULT(swapChain.queuePresent(queue, currentBuffer, submitOverlay ? semaphores.overlayComplete : semaphores.renderComplete)); + VkResult res = swapChain.queuePresent(queue, currentBuffer, submitOverlay ? semaphores.overlayComplete : semaphores.renderComplete); + if (!((res == VK_SUCCESS) || (res == VK_SUBOPTIMAL_KHR))) { + if (res == VK_ERROR_OUT_OF_DATE_KHR) { + // Swap chain is no longer compatible with the surface and needs to be recreated + windowResize(); + return; + } else { + VK_CHECK_RESULT(res); + } + } VK_CHECK_RESULT(vkQueueWaitIdle(queue)); }