Sfoglia il codice sorgente

win-capture: Fix Vulkan race condition

This race condition is caused when one thread creates a swap chain,
which calls OBS_CreateSwapchainKHR, at the same time another thread
calls OBS_CreateImageView.

OBS_CreateSwapchainKHR allocates swap data, publishes this into the
data->swaps linked list, then initializes it. Meanwhile,
OBS_CreateImageView is iterating the swaps linked list, to see if the
image matches any swap chain images. Due to the order in
OBS_CreateSwapchainKHR, there's no guarantee this data is initialized
so it often ends up running out of bounds on the swap_images array.

The fix is simply to defer the swap data publish to after init.

(cherry picked from commit aa1f2dea84e73ac1cdf167d0b9fd813880a66e08)
Seth Williams 2 anni fa
parent
commit
16e3faf0d0
1 ha cambiato i file con 1 aggiunte e 1 eliminazioni
  1. 1 1
      plugins/win-capture/graphics-hook/vulkan-capture.c

+ 1 - 1
plugins/win-capture/graphics-hook/vulkan-capture.c

@@ -1796,7 +1796,6 @@ OBS_CreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *cinfo,
 	if ((res == VK_SUCCESS) && (count > 0)) {
 		struct vk_swap_data *swap_data = alloc_swap_data(ac);
 		if (swap_data) {
-			init_swap_data(swap_data, data, sc);
 			swap_data->swap_images = vk_alloc(
 				ac, count * sizeof(VkImage), _Alignof(VkImage),
 				VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
@@ -1816,6 +1815,7 @@ OBS_CreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *cinfo,
 			swap_data->shtex_info = NULL;
 			swap_data->d3d11_tex = NULL;
 			swap_data->captured = false;
+			init_swap_data(swap_data, data, sc);
 		}
 	}