From 96f2aea4a67155583f69416a9472dafa813ccd0f Mon Sep 17 00:00:00 2001 From: kj16609 Date: Tue, 9 Jan 2024 09:41:06 -0500 Subject: [PATCH] Add better handling for submitting command buffer --- src/engine/SwapChain.cpp | 18 +++++++++++++++--- src/engine/SwapChain.hpp | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/engine/SwapChain.cpp b/src/engine/SwapChain.cpp index b1f1910..d62ce7e 100644 --- a/src/engine/SwapChain.cpp +++ b/src/engine/SwapChain.cpp @@ -108,10 +108,22 @@ namespace fgl::engine if ( Device::getInstance().device().resetFences( 1, &inFlightFences[ currentFrame ] ) != vk::Result::eSuccess ) throw std::runtime_error( "failed to reset fences!" ); - if ( Device::getInstance().graphicsQueue().submit( 1, &submitInfo, inFlightFences[ currentFrame ] ) - != vk::Result::eSuccess ) + if ( auto result = + Device::getInstance().graphicsQueue().submit( 1, &submitInfo, inFlightFences[ currentFrame ] ); + result != vk::Result::eSuccess ) { - throw std::runtime_error( "failed to submit draw command buffer!" ); + switch ( result ) + { + case vk::Result::eErrorOutOfDateKHR: + return vk::Result::eErrorOutOfDateKHR; + case vk::Result::eSuboptimalKHR: + return vk::Result::eSuboptimalKHR; + case vk::Result::eErrorDeviceLost: + throw std::runtime_error( "Device lost!" ); + default: + throw std::runtime_error( + "failed to submit draw command buffer!: ID" + std::to_string( static_cast< int >( result ) ) ); + } } vk::PresentInfoKHR presentInfo = {}; diff --git a/src/engine/SwapChain.hpp b/src/engine/SwapChain.hpp index 0dadcb7..a1b50b2 100644 --- a/src/engine/SwapChain.hpp +++ b/src/engine/SwapChain.hpp @@ -106,8 +106,8 @@ namespace fgl::engine vk::Format findDepthFormat(); - vk::Result acquireNextImage( uint32_t* imageIndex ); - vk::Result submitCommandBuffers( const vk::CommandBuffer* buffers, uint32_t* imageIndex ); + [[nodiscard]] vk::Result acquireNextImage( uint32_t* imageIndex ); + [[nodiscard]] vk::Result submitCommandBuffers( const vk::CommandBuffer* buffers, uint32_t* imageIndex ); }; } // namespace fgl::engine