vulkan/wsi: Simplify wsi_win32_surface_create_swapchain() error path
We are about to add more to this function, so let's try to automate the cleanup steps in the error path. Incrementing image_count as we add new images to the swapchain allows us to call wsi_win32_swapchain_destroy() even if not all images were initialized. Reviewed-by: Jesse Natalie <jenatali@microsoft.com> Reviewed-by: Daniel Stone <daniels@collabora.com> Acked-by: Jason Ekstrand <jason.ekstrand@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16200>
This commit is contained in:

committed by
Marge Bot

parent
52c87d0b83
commit
5fb2adb8fd
@@ -466,7 +466,6 @@ wsi_win32_surface_create_swapchain(
|
||||
chain->base.acquire_next_image = wsi_win32_acquire_next_image;
|
||||
chain->base.queue_present = wsi_win32_queue_present;
|
||||
chain->base.present_mode = wsi_swapchain_get_present_mode(wsi_device, create_info);
|
||||
chain->base.image_count = num_images;
|
||||
chain->extent = create_info->imageExtent;
|
||||
|
||||
chain->wsi = wsi;
|
||||
@@ -477,27 +476,22 @@ wsi_win32_surface_create_swapchain(
|
||||
assert(wsi_device->sw);
|
||||
chain->base.use_buffer_blit = true;
|
||||
|
||||
for (uint32_t image = 0; image < chain->base.image_count; image++) {
|
||||
for (uint32_t image = 0; image < num_images; image++) {
|
||||
result = wsi_win32_image_init(device, chain,
|
||||
create_info, allocator,
|
||||
&chain->images[image]);
|
||||
if (result != VK_SUCCESS) {
|
||||
while (image > 0) {
|
||||
--image;
|
||||
wsi_win32_image_finish(chain, allocator,
|
||||
&chain->images[image]);
|
||||
}
|
||||
wsi_swapchain_finish(&chain->base);
|
||||
vk_free(allocator, chain);
|
||||
goto fail_init_images;
|
||||
}
|
||||
if (result != VK_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
chain->base.image_count++;
|
||||
}
|
||||
|
||||
*swapchain_out = &chain->base;
|
||||
|
||||
return VK_SUCCESS;
|
||||
|
||||
fail_init_images:
|
||||
fail:
|
||||
wsi_win32_swapchain_destroy(&chain->base, allocator);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user