1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-12-18 02:26:06 +01:00

Proper destruction and device sync if resize is required

This commit is contained in:
Kleber Garcia 2024-03-07 16:45:16 -05:00
parent 286cd5bd41
commit 634554588a

View File

@ -397,10 +397,19 @@ static void CreateOrResizeBuffer(VkBuffer& buffer, VkDeviceMemory& buffer_memory
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData(); ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo; ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
VkResult err; VkResult err;
if (buffer != VK_NULL_HANDLE)
vkDestroyBuffer(v->Device, buffer, v->Allocator); // Destroy resources if they existed already
if (buffer_memory != VK_NULL_HANDLE) if (buffer != VK_NULL_HANDLE || buffer_memory != VK_NULL_HANDLE)
vkFreeMemory(v->Device, buffer_memory, v->Allocator); {
//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); VkDeviceSize buffer_size_aligned = AlignBufferSize(IM_MAX(v->MinAllocationSize, new_size), bd->BufferMemoryAlignment);
VkBufferCreateInfo buffer_info = {}; VkBufferCreateInfo buffer_info = {};