From db1f73fee4e21f478e8411bbca6184135f79058e Mon Sep 17 00:00:00 2001 From: Adam Sawicki Date: Mon, 13 Aug 2018 12:22:37 +0200 Subject: [PATCH] Improved handling of destruction calls with null handle, in vk_mem_alloc as well as VmaReplay. --- src/VmaReplay/VmaReplay.cpp | 42 +++++++++++++++++++++---------------- src/vk_mem_alloc.h | 21 +++++++++++++++---- 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/src/VmaReplay/VmaReplay.cpp b/src/VmaReplay/VmaReplay.cpp index 6462461..eaac603 100644 --- a/src/VmaReplay/VmaReplay.cpp +++ b/src/VmaReplay/VmaReplay.cpp @@ -765,17 +765,20 @@ void Player::ExecuteDestroyPool(size_t lineNumber, const CsvSplit& csvSplit) if(StrRangeToPtr(csvSplit.GetRange(FIRST_PARAM_INDEX), origPtr)) { - const auto it = m_Pools.find(origPtr); - if(it != m_Pools.end()) + if(origPtr != 0) { - vmaDestroyPool(m_Allocator, it->second.pool); - m_Pools.erase(it); - } - else - { - if(IssueWarning()) + const auto it = m_Pools.find(origPtr); + if(it != m_Pools.end()) { - printf("Line %zu: Pool %llX not found.\n", lineNumber, origPtr); + vmaDestroyPool(m_Allocator, it->second.pool); + m_Pools.erase(it); + } + else + { + if(IssueWarning()) + { + printf("Line %zu: Pool %llX not found.\n", lineNumber, origPtr); + } } } } @@ -867,17 +870,20 @@ void Player::DestroyAllocation(size_t lineNumber, const CsvSplit& csvSplit) if(StrRangeToPtr(csvSplit.GetRange(FIRST_PARAM_INDEX), origAllocPtr)) { - const auto it = m_Allocations.find(origAllocPtr); - if(it != m_Allocations.end()) + if(origAllocPtr != 0) { - Destroy(it->second); - m_Allocations.erase(it); - } - else - { - if(IssueWarning()) + const auto it = m_Allocations.find(origAllocPtr); + if(it != m_Allocations.end()) { - printf("Line %zu: Allocation %llX not found.\n", lineNumber, origAllocPtr); + Destroy(it->second); + m_Allocations.erase(it); + } + else + { + if(IssueWarning()) + { + printf("Line %zu: Allocation %llX not found.\n", lineNumber, origAllocPtr); + } } } } diff --git a/src/vk_mem_alloc.h b/src/vk_mem_alloc.h index 834adc5..6250dd6 100644 --- a/src/vk_mem_alloc.h +++ b/src/vk_mem_alloc.h @@ -9929,6 +9929,11 @@ void vmaFreeMemory( { VMA_ASSERT(allocator); + if(allocation == VK_NULL_HANDLE) + { + return; + } + { VmaMutexLock lock(g_FileMutex, true); EnsureFile(); @@ -9943,10 +9948,7 @@ void vmaFreeMemory( VMA_DEBUG_LOG("vmaFreeMemory"); VMA_DEBUG_GLOBAL_MUTEX_LOCK - if(allocation != VK_NULL_HANDLE) - { - allocator->FreeMemory(allocation); - } + allocator->FreeMemory(allocation); } void vmaGetAllocationInfo( @@ -10232,6 +10234,11 @@ void vmaDestroyBuffer( { VMA_ASSERT(allocator); + if(buffer == VK_NULL_HANDLE && allocation == VK_NULL_HANDLE) + { + return; + } + { VmaMutexLock lock(g_FileMutex, true); EnsureFile(); @@ -10356,6 +10363,12 @@ void vmaDestroyImage( { VMA_ASSERT(allocator); + if(image == VK_NULL_HANDLE && allocation == VK_NULL_HANDLE) + { + return; + } + + { VmaMutexLock lock(g_FileMutex, true); EnsureFile();