From 634554588a7168d1e69d0d0488544aa42f7c71a1 Mon Sep 17 00:00:00 2001 From: Kleber Garcia Date: Thu, 7 Mar 2024 16:45:16 -0500 Subject: [PATCH] Proper destruction and device sync if resize is required --- backends/imgui_impl_vulkan.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/backends/imgui_impl_vulkan.cpp b/backends/imgui_impl_vulkan.cpp index a8962ecd2..57da9b2b9 100644 --- a/backends/imgui_impl_vulkan.cpp +++ b/backends/imgui_impl_vulkan.cpp @@ -397,10 +397,19 @@ static void CreateOrResizeBuffer(VkBuffer& buffer, VkDeviceMemory& buffer_memory ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData(); ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo; VkResult err; - if (buffer != VK_NULL_HANDLE) - vkDestroyBuffer(v->Device, buffer, v->Allocator); - if (buffer_memory != VK_NULL_HANDLE) - vkFreeMemory(v->Device, buffer_memory, v->Allocator); + + // Destroy resources if they existed already + if (buffer != VK_NULL_HANDLE || buffer_memory != VK_NULL_HANDLE) + { + //sync device to avoid deleting buffers that might be used by the gpu in a command list. + err = vkDeviceWaitIdle(v->Device); + check_vk_result(err); + + if (buffer != VK_NULL_HANDLE) + vkDestroyBuffer(v->Device, buffer, v->Allocator); + if (buffer_memory != VK_NULL_HANDLE) + vkFreeMemory(v->Device, buffer_memory, v->Allocator); + } VkDeviceSize buffer_size_aligned = AlignBufferSize(IM_MAX(v->MinAllocationSize, new_size), bd->BufferMemoryAlignment); VkBufferCreateInfo buffer_info = {};