@@ -514,13 +514,18 @@ class HelloTriangleApplication
514514
515515 auto [result, imageIndex] = swapChain.acquireNextImage (UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr );
516516
517+ // Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
518+ // here and does not need to be caught by an exception.
517519 if (result == vk::Result::eErrorOutOfDateKHR)
518520 {
519521 recreateSwapChain ();
520522 return ;
521523 }
524+ // On other success codes than eSuccess and eSuboptimalKHR we just throw an exception.
525+ // On any error code, aquireNextImage already threw an exception.
522526 if (result != vk::Result::eSuccess && result != vk::Result::eSuboptimalKHR)
523527 {
528+ assert (result == vk::Result::eTimeout || result == vk::Result::eNotReady);
524529 throw std::runtime_error (" failed to acquire swap chain image!" );
525530 }
526531
@@ -537,35 +542,23 @@ class HelloTriangleApplication
537542 .pSignalSemaphores = &*renderFinishedSemaphores[imageIndex]};
538543 queue.submit (submitInfo, *inFlightFences[frameIndex]);
539544
540- try
545+ const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1 ,
546+ .pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
547+ .swapchainCount = 1 ,
548+ .pSwapchains = &*swapChain,
549+ .pImageIndices = &imageIndex};
550+ result = queue.presentKHR (presentInfoKHR);
551+ // Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
552+ // here and does not need to be caught by an exception.
553+ if ((result == vk::Result::eSuboptimalKHR) || (result == vk::Result::eErrorOutOfDateKHR) || framebufferResized)
541554 {
542- const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1 ,
543- .pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
544- .swapchainCount = 1 ,
545- .pSwapchains = &*swapChain,
546- .pImageIndices = &imageIndex};
547- result = queue.presentKHR (presentInfoKHR);
548- if (result == vk::Result::eSuboptimalKHR || framebufferResized)
549- {
550- framebufferResized = false ;
551- recreateSwapChain ();
552- }
553- else if (result != vk::Result::eSuccess)
554- {
555- throw std::runtime_error (" failed to present swap chain image!" );
556- }
555+ framebufferResized = false ;
556+ recreateSwapChain ();
557557 }
558- catch ( const vk::SystemError &e)
558+ else
559559 {
560- if (e.code ().value () == static_cast <int >(vk::Result::eErrorOutOfDateKHR))
561- {
562- recreateSwapChain ();
563- return ;
564- }
565- else
566- {
567- throw ;
568- }
560+ // There are no other success codes than eSuccess; on any error code, presentKHR already threw an exception.
561+ assert (result == vk::Result::eSuccess);
569562 }
570563 frameIndex = (frameIndex + 1 ) % MAX_FRAMES_IN_FLIGHT;
571564 }
0 commit comments