From 1022be64cfc283ade477ca38f6384cd676a7fb04 Mon Sep 17 00:00:00 2001 From: Adam Sawicki Date: Wed, 22 Jun 2022 12:48:27 +0200 Subject: [PATCH] Added missing mutex when unmapping memory. Hopefully fixes #267. Code by @medranSolus --- include/vk_mem_alloc.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/vk_mem_alloc.h b/include/vk_mem_alloc.h index cd88e65..bdb4ff5 100644 --- a/include/vk_mem_alloc.h +++ b/include/vk_mem_alloc.h @@ -5907,7 +5907,7 @@ public: // Call when allocation/free was made from m_pMetadata. // Used for m_MappingHysteresis. - void PostAlloc() { m_MappingHysteresis.PostAlloc(); } + void PostAlloc(VmaAllocator hAllocator); void PostFree(VmaAllocator hAllocator); // Validates all data structures inside this object. If not valid, returns false. @@ -11765,8 +11765,15 @@ void VmaDeviceMemoryBlock::Destroy(VmaAllocator allocator) m_pMetadata = VMA_NULL; } +void VmaDeviceMemoryBlock::PostAlloc(VmaAllocator hAllocator) +{ + VmaMutexLock lock(m_MapAndBindMutex, hAllocator->m_UseMutex); + m_MappingHysteresis.PostAlloc(); +} + void VmaDeviceMemoryBlock::PostFree(VmaAllocator hAllocator) { + VmaMutexLock lock(m_MapAndBindMutex, hAllocator->m_UseMutex); if(m_MappingHysteresis.PostFree()) { VMA_ASSERT(m_MappingHysteresis.GetExtraMapping() == 0); @@ -12775,7 +12782,7 @@ VkResult VmaBlockVector::CommitAllocationRequest( const bool isMappingAllowed = (allocFlags & (VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT)) != 0; - pBlock->PostAlloc(); + pBlock->PostAlloc(m_hAllocator); // Allocate from pCurrBlock. if (mapped) {