@@ -348,6 +348,7 @@ class VulkanApplication {
348348 glfwInit ();
349349
350350 glfwWindowHint (GLFW_CLIENT_API, GLFW_NO_API);
351+ glfwWindowHint (GLFW_RESIZABLE, GLFW_TRUE);
351352
352353 window = glfwCreateWindow (WIDTH, HEIGHT, " Vulkan" , nullptr , nullptr );
353354 glfwSetWindowUserPointer (window, this );
@@ -1437,19 +1438,28 @@ class VulkanApplication {
14371438 };
14381439 queue.submit (submitInfo, *inFlightFences[currentFrame]);
14391440
1440- const vk::PresentInfoKHR presentInfoKHR{
1441- .waitSemaphoreCount = 1 ,
1442- .pWaitSemaphores = &*renderFinishedSemaphore[imageIndex],
1443- .swapchainCount = 1 ,
1444- .pSwapchains = &*swapChain,
1445- .pImageIndices = &imageIndex
1446- };
1447- result = queue.presentKHR (presentInfoKHR);
1448- if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized) {
1449- framebufferResized = false ;
1450- recreateSwapChain ();
1451- } else if (result != vk::Result::eSuccess) {
1452- throw std::runtime_error (" failed to present swap chain image!" );
1441+ try {
1442+ const vk::PresentInfoKHR presentInfoKHR{
1443+ .waitSemaphoreCount = 1 ,
1444+ .pWaitSemaphores = &*renderFinishedSemaphore[imageIndex],
1445+ .swapchainCount = 1 ,
1446+ .pSwapchains = &*swapChain,
1447+ .pImageIndices = &imageIndex
1448+ };
1449+ result = queue.presentKHR (presentInfoKHR);
1450+ if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized) {
1451+ framebufferResized = false ;
1452+ recreateSwapChain ();
1453+ } else if (result != vk::Result::eSuccess) {
1454+ throw std::runtime_error (" failed to present swap chain image!" );
1455+ }
1456+ } catch (const vk::SystemError& e) {
1457+ if (e.code ().value () == static_cast <int >(vk::Result::eErrorOutOfDateKHR)) {
1458+ recreateSwapChain ();
1459+ return ;
1460+ } else {
1461+ throw ;
1462+ }
14531463 }
14541464 currentFrame = (currentFrame + 1 ) % MAX_FRAMES_IN_FLIGHT;
14551465 }
0 commit comments