@@ -532,13 +532,18 @@ class HelloTriangleApplication
532532
533533 auto [result, imageIndex] = swapChain.acquireNextImage (UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr );
534534
535+ // Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
536+ // here and does not need to be caught by an exception.
535537 if (result == vk::Result::eErrorOutOfDateKHR)
536538 {
537539 recreateSwapChain ();
538540 return ;
539541 }
542+ // On other success codes than eSuccess and eSuboptimalKHR we just throw an exception.
543+ // On any error code, aquireNextImage already threw an exception.
540544 if (result != vk::Result::eSuccess && result != vk::Result::eSuboptimalKHR)
541545 {
546+ assert (result == vk::Result::eTimeout || result == vk::Result::eNotReady);
542547 throw std::runtime_error (" failed to acquire swap chain image!" );
543548 }
544549
@@ -556,37 +561,25 @@ class HelloTriangleApplication
556561 .pSignalSemaphores = &*renderFinishedSemaphores[imageIndex]};
557562 queue.submit (submitInfo, *inFlightFences[frameIndex]);
558563
559- try
564+ const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1 ,
565+ .pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
566+ .swapchainCount = 1 ,
567+ .pSwapchains = &*swapChain,
568+ .pImageIndices = &imageIndex};
569+ result = queue.presentKHR (presentInfoKHR);
570+ // Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
571+ // here and does not need to be caught by an exception.
572+ if ((result == vk::Result::eSuboptimalKHR) || (result == vk::Result::eErrorOutOfDateKHR) || framebufferResized)
560573 {
561- const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1 ,
562- .pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
563- .swapchainCount = 1 ,
564- .pSwapchains = &*swapChain,
565- .pImageIndices = &imageIndex};
566- result = queue.presentKHR (presentInfoKHR);
567- if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized)
568- {
569- framebufferResized = false ;
570- recreateSwapChain ();
571- }
572- else if (result != vk::Result::eSuccess)
573- {
574- throw std::runtime_error (" failed to present swap chain image!" );
575- }
574+ framebufferResized = false ;
575+ recreateSwapChain ();
576576 }
577- catch ( const vk::SystemError &e)
577+ else
578578 {
579- if (e.code ().value () == static_cast <int >(vk::Result::eErrorOutOfDateKHR))
580- {
581- recreateSwapChain ();
582- return ;
583- }
584- else
585- {
586- throw ;
587- }
579+ // There are no other success codes than eSuccess; on any error code, presentKHR already threw an exception.
580+ assert (result == vk::Result::eSuccess);
588581 }
589- frameIndex = (frameIndex + 1 ) % MAX_FRAMES_IN_FLIGHT;
582+ frameIndex = (frameIndex + 1 ) % MAX_FRAMES_IN_FLIGHT;
590583 }
591584
592585 [[nodiscard]] vk::raii::ShaderModule createShaderModule (const std::vector<char > &code) const
0 commit comments