From 3285d1ad8c92025711ee754f57fdb780012d80c1 Mon Sep 17 00:00:00 2001 From: Giovanni Mascellani Date: Wed, 9 Oct 2024 16:43:25 +0200 Subject: [PATCH] tests: Only destroy the device if the context has one in vulkan_test_context_destroy(). If vulkan_test_context_init_device() was never called, or failed to create a device, the context won't have a device. --- tests/vulkan_utils.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/vulkan_utils.h b/tests/vulkan_utils.h index cb5f3970..5f55625b 100644 --- a/tests/vulkan_utils.h +++ b/tests/vulkan_utils.h @@ -342,6 +342,16 @@ static inline bool get_vulkan_queue_index(const struct vulkan_test_context *cont return false; } +static inline void vulkan_test_context_destroy_device(const struct vulkan_test_context *context) +{ + VkDevice device = context->device; + + VK_CALL(vkDestroyDescriptorPool(device, context->descriptor_pool, NULL)); + VK_CALL(vkFreeCommandBuffers(device, context->command_pool, 1, &context->cmd_buffer)); + VK_CALL(vkDestroyCommandPool(device, context->command_pool, NULL)); + VK_CALL(vkDestroyDevice(device, NULL)); +} + static inline bool vulkan_test_context_init_device(struct vulkan_test_context *context, const VkDeviceCreateInfo *device_desc, uint32_t queue_index, uint32_t max_resource_count, uint32_t max_sampler_count) @@ -402,12 +412,8 @@ static inline bool vulkan_test_context_init_device(struct vulkan_test_context *c static inline void vulkan_test_context_destroy(const struct vulkan_test_context *context) { - VkDevice device = context->device; - - VK_CALL(vkDestroyDescriptorPool(device, context->descriptor_pool, NULL)); - VK_CALL(vkFreeCommandBuffers(device, context->command_pool, 1, &context->cmd_buffer)); - VK_CALL(vkDestroyCommandPool(device, context->command_pool, NULL)); - VK_CALL(vkDestroyDevice(device, NULL)); + if (context->device) + vulkan_test_context_destroy_device(context); VK_CALL(vkDestroyInstance(context->instance, NULL)); }