@@ -532,17 +532,24 @@ 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
550+ // Only reset the fence if we are submitting work
545551 device.resetFences (*inFlightFences[frameIndex]);
552+
546553 commandBuffers[frameIndex].reset ();
547554 recordCommandBuffer (imageIndex);
548555
@@ -556,37 +563,25 @@ class HelloTriangleApplication
556563 .pSignalSemaphores = &*renderFinishedSemaphores[imageIndex]};
557564 queue.submit (submitInfo, *inFlightFences[frameIndex]);
558565
559- try
566+ const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1 ,
567+ .pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
568+ .swapchainCount = 1 ,
569+ .pSwapchains = &*swapChain,
570+ .pImageIndices = &imageIndex};
571+ result = queue.presentKHR (presentInfoKHR);
572+ // Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
573+ // here and does not need to be caught by an exception.
574+ if ((result == vk::Result::eSuboptimalKHR) || (result == vk::Result::eErrorOutOfDateKHR) || framebufferResized)
560575 {
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- }
576+ framebufferResized = false ;
577+ recreateSwapChain ();
576578 }
577- catch ( const vk::SystemError &e)
579+ else
578580 {
579- if (e.code ().value () == static_cast <int >(vk::Result::eErrorOutOfDateKHR))
580- {
581- recreateSwapChain ();
582- return ;
583- }
584- else
585- {
586- throw ;
587- }
581+ // There are no other success codes than eSuccess; on any error code, presentKHR already threw an exception.
582+ assert (result == vk::Result::eSuccess);
588583 }
589- frameIndex = (frameIndex + 1 ) % MAX_FRAMES_IN_FLIGHT;
584+ frameIndex = (frameIndex + 1 ) % MAX_FRAMES_IN_FLIGHT;
590585 }
591586
592587 [[nodiscard]] vk::raii::ShaderModule createShaderModule (const std::vector<char > &code) const
0 commit comments