From 6530fe3a38fde2ea0183cde8acd011777da42e53 Mon Sep 17 00:00:00 2001 From: Adam Sawicki Date: Wed, 4 Apr 2018 10:54:27 +0200 Subject: [PATCH] Fixed vmaDestroyBuffer, vmaDestroyImage, vmaFreeMemory for cases where allocation is null. #24 thanks @achienbsi ! --- src/vk_mem_alloc.h | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/vk_mem_alloc.h b/src/vk_mem_alloc.h index fb29a17..2b48da8 100644 --- a/src/vk_mem_alloc.h +++ b/src/vk_mem_alloc.h @@ -9089,13 +9089,13 @@ void vmaFreeMemory( VmaAllocator allocator, VmaAllocation allocation) { - VMA_ASSERT(allocator && allocation); - + VMA_ASSERT(allocator); VMA_DEBUG_LOG("vmaFreeMemory"); - VMA_DEBUG_GLOBAL_MUTEX_LOCK - - allocator->FreeMemory(allocation); + if(allocation != VK_NULL_HANDLE) + { + allocator->FreeMemory(allocation); + } } void vmaGetAllocationInfo( @@ -9303,16 +9303,15 @@ void vmaDestroyBuffer( VkBuffer buffer, VmaAllocation allocation) { + VMA_ASSERT(allocator); + VMA_DEBUG_LOG("vmaDestroyBuffer"); + VMA_DEBUG_GLOBAL_MUTEX_LOCK if(buffer != VK_NULL_HANDLE) { - VMA_ASSERT(allocator); - - VMA_DEBUG_LOG("vmaDestroyBuffer"); - - VMA_DEBUG_GLOBAL_MUTEX_LOCK - (*allocator->GetVulkanFunctions().vkDestroyBuffer)(allocator->m_hDevice, buffer, allocator->GetAllocationCallbacks()); - + } + if(allocation != VK_NULL_HANDLE) + { allocator->FreeMemory(allocation); } } @@ -9379,16 +9378,15 @@ void vmaDestroyImage( VkImage image, VmaAllocation allocation) { + VMA_ASSERT(allocator); + VMA_DEBUG_LOG("vmaDestroyImage"); + VMA_DEBUG_GLOBAL_MUTEX_LOCK if(image != VK_NULL_HANDLE) { - VMA_ASSERT(allocator); - - VMA_DEBUG_LOG("vmaDestroyImage"); - - VMA_DEBUG_GLOBAL_MUTEX_LOCK - (*allocator->GetVulkanFunctions().vkDestroyImage)(allocator->m_hDevice, image, allocator->GetAllocationCallbacks()); - + } + if(allocation != VK_NULL_HANDLE) + { allocator->FreeMemory(allocation); } }