Skip to content

Incorrect checking for eErrorOutOfDateKHR #220

@emackey

Description

@emackey

I noticed this on Windows 11 after seeing crashes when resizing.

Several tutorial steps here feature explicit checks for return value of eErrorOutOfDateKHR. For example from presentKHR:

result = queue.presentKHR( presentInfoKHR );
if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized) {

And also from acquireNextImage:

auto [result, imageIndex] = swapChain.acquireNextImage( UINT64_MAX, *presentCompleteSemaphore[semaphoreIndex], nullptr );
if (result == vk::Result::eErrorOutOfDateKHR) {

However, it is impossible for either of these tests to evaluate to true, because eErrorOutOfDateKHR is considered to be an error condition, and will always throw an exception from vulkan_hpp. It will never be returned as an actual return value as suggested here.

Indeed, issue KhronosGroup/Vulkan-Hpp#599 was filed against vulkan_hpp to stop the exception. But this issue was closed, because the hpp is automatically generated, and the enum in question is marked as a true error condition. So, the hpp will always throw for this condition, even if it's just because the window changed size, crashing the tutorial.

For what it's worth, in my own code I'm making the call a different way, avoiding the exception:

    result = static_cast<vk::Result>(queue.getDispatcher()->vkQueuePresentKHR(*queue, presentInfoKHR));

This looks a bit messier, and it circumvents the hpp's result checking and exception-throwing. So it's important to inspect result carefully and throw one's own exceptions as needed, except in the case of eErrorOutOfDateKHR of course, which just requires the swapchain to be recreated with the new size.

I'm not sure if the above type of code is appropriate for this tutorial. But at the very least, the tutorial should not have if statements suggesting that this particular enum would ever be seen as a return value, because vulkan_hpp will have already thrown an exception on it.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions