vk_swapchain_t *chain;
VkResult error;
uint32_t i;
+ uint32_t cnt_success = 0;
tbm_surface_h *buffers;
tbm_format format;
vk_icd_t *icd = vk_get_icd();
chain->allocator = allocator;
chain->surface = info->surface;
+ chain->buffers = NULL;
format = get_tbm_format(info->imageFormat, info->compositeAlpha);
VK_CHECK(format, return VK_ERROR_SURFACE_LOST_KHR, "Not supported image format.\n");
};
chain->buffers[i].tbm = buffers[i];
- icd->create_presentable_image(device, chain->buffers[i].tbm, &image_info,
- allocator, &chain->buffers[i].image);
+ error = icd->create_presentable_image(device, chain->buffers[i].tbm, &image_info,
+ allocator, &chain->buffers[i].image);
+ VK_CHECK(error == VK_SUCCESS, goto done, "create_presentable_image failed.\n");
+
+ cnt_success++;
}
goto done;
done:
if (error != VK_SUCCESS) {
+ if (cnt_success > 0) {
+ PFN_vkGetDeviceProcAddr icd_gdpa = (PFN_vkGetDeviceProcAddr)icd->get_proc_addr(NULL, "vkGetDeviceProcAddr");
+ if (icd_gdpa != VK_NULL_HANDLE) {
+ PFN_vkDestroyImage destroy_image = (PFN_vkDestroyImage)icd_gdpa(device, "vkDestroyImage");
+ if (destroy_image != VK_NULL_HANDLE) {
+ for (i = 0; i < cnt_success; i++)
+ destroy_image(device, chain->buffers[i].image, allocator);
+ }
+ }
+ }
+
+ if (chain->buffers) {
+ vk_free(allocator, chain->buffers);
+ chain->buffers = NULL;
+ }
+
if (chain->deinit)
chain->deinit(device, chain);
- if (chain)
+ if (chain) {
vk_free(allocator, chain);
+ chain = NULL;
+ }
*swapchain = VK_NULL_HANDLE;
} else {