vulkan-renderer icon indicating copy to clipboard operation
vulkan-renderer copied to clipboard

Resizing the window quickly throws an exception on Ubuntu

Open IAmNotHanni opened this issue 4 years ago • 7 comments

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:

  1. Launch the program (with or without debugger)
  2. 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.)

IAmNotHanni avatar Apr 22 '21 14:04 IAmNotHanni

This occurs in both hanni/octree_collision and yeetari/warning-cleanup. I will check it on MS Windows now.

IAmNotHanni avatar Apr 22 '21 14:04 IAmNotHanni

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?

IAmNotHanni avatar Apr 22 '21 14:04 IAmNotHanni

One thing we could do is to recreate swapchain only of window has been resized and the left mouse button was lifted up.

IAmNotHanni avatar May 02 '21 18:05 IAmNotHanni

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.

IAmNotHanni avatar Jul 21 '21 20:07 IAmNotHanni

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.

IAmNotHanni avatar Jul 25 '21 18:07 IAmNotHanni

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!

IAmNotHanni avatar Jul 25 '21 18:07 IAmNotHanni

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 currentExtent is set to 0xFFFFFFFF, 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.

IAmNotHanni avatar Jul 25 '21 19:07 IAmNotHanni

Resizing the window quickly multiple times also causes this issue on Windows 10:

image

IAmNotHanni avatar Oct 08 '22 18:10 IAmNotHanni

I found a solution (see pr)

IAmNotHanni avatar Mar 06 '23 16:03 IAmNotHanni

This bug has been solved by #523

IAmNotHanni avatar May 13 '23 15:05 IAmNotHanni