I am currently implementing swap chain re-creation after window-resize. I am using Vulkan-Hpp, so I am posting some rather Vulkan-Hpp-ish pseudocode. My basic approach is as follows:
try {
Call to vk::Queue::presentKHR // this one throws an vk::OutOfDateKHRError exception
}
catch (vk::OutOfDateKHRError omg) {
// recreating the swap chain
vk::SwapchainCreateInfoKHR createInfo;
createInfo.oldSwapchain = /* Passing the old, now out of date, swapchain handle */;
/* All the other parameters of createInfo are set to the same values of the oldSwapchain */
vk::Device::createSwapchainKHRUnique(createInfo); // Fails with access violation IRREGULARLY
}
createSwapchainKHRUnique
sometimes causes an access violation while it works just fine most of the time. I.e. I try it ~20 times, it works ~19 times and fails ~1 time with the following error message:
Exception thrown at 0x00007FFED1D4A5C5 (nvoglv64.dll) in hello_world.exe: 0xC0000005: Access violation writing location 0x0000000000000038.
I don’t think that my general approach is wrong, otherwise it would not work at all. My question is: What could I be overlooking? Why would an access violation occur irregularly? What does it mean writing location 0x0000000000000038
? => Can this be related to the swap chain images somehow? How could I narrow down the error?
I’ve also tried to put a vk::Device::waitIdle
call right before the invocation of vk::Device::createSwapchainKHRUnique
but that doesn’t help. Are there any good reference implementations for swap chain re-creation that use the createInfo.oldSwapchain
parameter which I could have a look at?