GPUOpen-LibrariesAndSDKs / VulkanMemoryAllocator

Easy to integrate Vulkan memory allocation library
MIT License
2.63k stars 359 forks source link

vmaDestroyBuffer() destroy everything but VkDeviceMemory #401

Open ghost opened 9 months ago

ghost commented 9 months ago

When I vmaDestroyBuffer(), at object destruction, it doesn't destroy VkDeviceMemory hMemory, resulting in error:

Validation Error: [ VUID-vkDestroyDevice-device-05137 ] Object 0: handle = 0x2e2941000000001f, type = VK_OBJECT_TYPE_DEVICE_MEMORY; | MessageID = 0x4872eaa0 | vkCreateDevice(): OBJ ERROR : For VkDevice 0x156f8145c70[], VkDeviceMemory 0x2e2941000000001f[] has not been destroyed. The Vulkan spec states: All child objects created on device must have been destroyed prior to destroying device (https://vulkan.lunarg.com/doc/view/1.3.268.0/windows/1.3-extensions/vkspec.html#VUID-vkDestroyDevice-device-05137) ERROR: vkFreeMemory: Invalid device [VUID-vkFreeMemory-device-parameter]

after i destroy my device.

adam-sawicki-a commented 9 months ago

Function vmaCreateBuffer creates two objects: VkBuffer and VmaAllocation. When the buffer is no longer needed, you should destroy them both by passing them to vmaDestroyBuffer. Do you pass them both, the buffer and the allocation object?

An allocation represents a piece of device memory.

You don't need to think about it as long as you respect the correct order of deinitialization, which is:

for each buffer:
    vmaDestroyBuffer(g_Allocator, buffer[i], bufferAllocation[i]);
vmaDestroyAllocator(g_Allocator);
vkDestroyDevice(...);

So, my main question is: Did you call vmaDestroyAllocator?

xbz-24 commented 7 months ago

I have the same question and calling the vmaDestroyAllocator didnt do the trick

xbz-24 commented 7 months ago

I managed to do a very brief MRE, minimal reproducible example.

    vmaDestroyBuffer(m_allocator, m_vertex_buffer.buffer, m_vertex_buffer.allocation);
    vmaDestroyAllocator(m_allocator);

e.g.

[2024-03-29 17:47:02.921] [info] validation layer: Validation Error: [ VUID-vkDestroyDevice-device-05137 ] Object 0: handle = 0x908683000000001d, type = VK_OBJECT_TYPE_DEVICE_MEMORY; | MessageID = 0x4872eaa0 | vkCreateDevice(): OBJ ERROR : For VkDevice 0x11729a118[], VkDeviceMemory 0x908683000000001d[] has not been destroyed. The Vulkan spec states: All child objects created on device must have been destroyed prior to destroying device

M2-TE commented 7 months ago

Do make sure to destroy the allocator prior to the device according to deinitialization order as mentioned by @adam-sawicki-a ; not doing so is only case where I seem to be able to reproduce that error