From 5fb2adb8fdbe1acba185d02bbc2fa74bcff488c5 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Thu, 28 Apr 2022 00:03:04 -0700 Subject: [PATCH] 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 Reviewed-by: Daniel Stone Acked-by: Jason Ekstrand Part-of: --- src/vulkan/wsi/wsi_common_win32.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/vulkan/wsi/wsi_common_win32.c b/src/vulkan/wsi/wsi_common_win32.c index 0dc1a359cf8..d53fb782128 100644 --- a/src/vulkan/wsi/wsi_common_win32.c +++ b/src/vulkan/wsi/wsi_common_win32.c @@ -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; }