Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions en/03_Drawing_a_triangle/04_Swap_chain_recreation.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,38 @@ currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
The `vkQueuePresentKHR` function returns the same values with the same meaning.
In this case, we will also recreate the swap chain if it is suboptimal, because we want the best possible result.

[,c++]
----
try
{
const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1, .pWaitSemaphores = &*renderFinishedSemaphore[imageIndex], .swapchainCount = 1, .pSwapchains = &*swapChain, .pImageIndices = &imageIndex};
result = queue.presentKHR(presentInfoKHR);
if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized)
{
framebufferResized = false;
recreateSwapChain();
}
else if (result != vk::Result::eSuccess)
{
throw std::runtime_error("failed to present swap chain image!");
}
}
catch (const vk::SystemError &e)
{
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR))
{
recreateSwapChain();
return;
}
else
{
throw;
}
}
----

Recent versions of the Vulkan CPP header throw exceptions on unsuccessful return codes. To handle exceptions thrown by `vkQueuePresentKHR`, catch `vk::SystemError` and check the error code as shown above.

== Fixing a deadlock

If we try to run the code now, it is possible to encounter a deadlock.
Expand Down
Loading