vulkan-renderer
vulkan-renderer copied to clipboard
Resizing the window quickly throws an exception on Ubuntu
Describe the bug If I quickly resize vulkan-renderer's window on Ubuntu 20.04 in debug mode, the program crashes.
To Reproduce Steps to reproduce the behavior:
- Launch the program (with or without debugger)
- Resize the window frequently
Expected behavior Swapchain recreation should succeed.
Console
2021-04-22 16:42:45.288721 debug 10446 [vulkan-renderer] Deciding automatically which surface color format in swapchain to use.
terminate called after throwing an instance of 'inexor::vulkan_renderer::VulkanException'
what(): Error: vkCreateSwapchainKHR failed! (VK_ERROR_INITIALIZATION_FAILED: Initialization of an object could not be completed for implementation-specific reasons.)
This occurs in both hanni/octree_collision and yeetari/warning-cleanup.
I will check it on MS Windows now.
Ok so under Windows this crash does not occur. This means there's something wrong with the way we handle swapchain recreation, at least for Linux based systems I guess?
One thing we could do is to recreate swapchain only of window has been resized and the left mouse button was lifted up.
Ok so I think there is no solution to this problem: Other Linux users didn't report my problem so I think it's a driver issue. I tried to recreate the swapchain only if the left mouse button if not pressed, but that didn't fix it either. It's up to Intel Mesa driver to fix this.
Thanks to user blopr from Discord, we know that this is not a driver issue, but it looks like it's a bug in our swapchain creation code. It could be that the swapchain settings obtained by vkGetPhysicalDeviceSurfaceCapabilitiesKHR are outdated by the time we call vkCreateSwapchainKHR if we resize the window very fast.
2021-07-25 20:51:25.621544 error 17579 [vulkan-renderer] Validation Error: [ VUID-VkSwapchainCreateInfoKHR-imageExtent-01274 ] Object 0: handle = 0x564765ab7220, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x7cd0911d | vkCreateSwapchainKHR() called with imageExtent = (654,654), which is outside the bounds returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): currentExtent = (654,800), minImageExtent = (654,800), maxImageExtent = (654,800). The Vulkan spec states: imageExtent must be between minImageExtent and maxImageExtent, inclusive, where minImageExtent and maxImageExtent are members of the VkSurfaceCapabilitiesKHR structure returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR for the surface (https://vulkan.lunarg.com/doc/view/1.2.182.0/linux/1.2-extensions/vkspec.html#VUID-VkSwapchainCreateInfoKHR-imageExtent-01274) 2021-07-25 20:51:25.621564 critical 17579 [vulkan-renderer] Command line argument --stop-on-validation-message is enabled. 2021-07-25 20:51:25.621590 critical 17579 [vulkan-renderer] Application will cause a break point now!
So the problem is this code passage:
// If width (and height) equals the special value 0xFFFFFFFF, the size of the surface will
// be set by the swapchain.
if (surface_capabilities.currentExtent.width == std::numeric_limits<std::uint32_t>::max() ||
surface_capabilities.currentExtent.height == std::numeric_limits<std::uint32_t>::max()) {
// The size of the window dictates the extent of the swapchain.
swapchain_size.width = window_width;
swapchain_size.height = window_height;
} else {
// If the surface size is defined, the swapchain size must match.
swapchain_size = surface_capabilities.currentExtent;
}
The problem
- If
currentExtentis set to0xFFFFFFFF, the swapchain size can be defined by the current window width and height. - Otherwise, both the swapchain size and the window's width and height must match
currentExtent! We are not respecting that so far.
Resizing the window quickly multiple times also causes this issue on Windows 10:

I found a solution (see pr)
This bug has been solved by #523