@@ -511,13 +511,18 @@ class HelloTriangleApplication
511511
512512 auto [result, imageIndex] = swapChain.acquireNextImage (UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr );
513513
514+ // Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
515+ // here and does not need to be caught by an exception.
514516 if (result == vk::Result::eErrorOutOfDateKHR)
515517 {
516518 recreateSwapChain ();
517519 return ;
518520 }
521+ // On other success codes than eSuccess and eSuboptimalKHR we just throw an exception.
522+ // On any error code, aquireNextImage already threw an exception.
519523 if (result != vk::Result::eSuccess && result != vk::Result::eSuboptimalKHR)
520524 {
525+ assert (result == vk::Result::eTimeout || result == vk::Result::eNotReady);
521526 throw std::runtime_error (" failed to acquire swap chain image!" );
522527 }
523528
@@ -535,35 +540,23 @@ class HelloTriangleApplication
535540 .pSignalSemaphores = &*renderFinishedSemaphores[imageIndex]};
536541 queue.submit (submitInfo, *inFlightFences[frameIndex]);
537542
538- try
543+ const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1 ,
544+ .pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
545+ .swapchainCount = 1 ,
546+ .pSwapchains = &*swapChain,
547+ .pImageIndices = &imageIndex};
548+ result = queue.presentKHR (presentInfoKHR);
549+ // Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
550+ // here and does not need to be caught by an exception.
551+ if ((result == vk::Result::eSuboptimalKHR) || (result == vk::Result::eErrorOutOfDateKHR) || framebufferResized)
539552 {
540- const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1 ,
541- .pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
542- .swapchainCount = 1 ,
543- .pSwapchains = &*swapChain,
544- .pImageIndices = &imageIndex};
545- result = queue.presentKHR (presentInfoKHR);
546- if (result == vk::Result::eSuboptimalKHR || framebufferResized)
547- {
548- framebufferResized = false ;
549- recreateSwapChain ();
550- }
551- else if (result != vk::Result::eSuccess)
552- {
553- throw std::runtime_error (" failed to present swap chain image!" );
554- }
553+ framebufferResized = false ;
554+ recreateSwapChain ();
555555 }
556- catch ( const vk::SystemError &e)
556+ else
557557 {
558- if (e.code ().value () == static_cast <int >(vk::Result::eErrorOutOfDateKHR))
559- {
560- recreateSwapChain ();
561- return ;
562- }
563- else
564- {
565- throw ;
566- }
558+ // There are no other success codes than eSuccess; on any error code, presentKHR already threw an exception.
559+ assert (result == vk::Result::eSuccess);
567560 }
568561 frameIndex = (frameIndex + 1 ) % MAX_FRAMES_IN_FLIGHT;
569562 }
0 commit comments