Skip to content

Commit 7b9c21f

Browse files
committed
Fixed defragmenter not acquiring a lock before touching blocks
1 parent 44a5aea commit 7b9c21f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

include/vk_mem_alloc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10909,6 +10909,7 @@ class VmaBlockVector
1090910909
size_t GetBlockCount() const { return m_Blocks.size(); }
1091010910
// To be used only while the m_Mutex is locked. Used during defragmentation.
1091110911
VmaDeviceMemoryBlock* GetBlock(size_t index) const { return m_Blocks[index]; }
10912+
VMA_RW_MUTEX &GetMutex() { return m_Mutex; }
1091210913

1091310914
VkResult CreateMinBlocks();
1091410915
void AddStatistics(VmaStatistics& inoutStats);
@@ -13064,6 +13065,8 @@ VkResult VmaDefragmentationContext_T::DefragmentPassBegin(VmaDefragmentationPass
1306413065
{
1306513066
if (m_PoolBlockVector != VMA_NULL)
1306613067
{
13068+
VmaMutexLockWrite lock(m_PoolBlockVector->GetMutex(), m_PoolBlockVector->GetAllocator()->m_UseMutex);
13069+
1306713070
if (m_PoolBlockVector->GetBlockCount() > 1)
1306813071
ComputeDefragmentation(*m_PoolBlockVector, 0);
1306913072
else if (m_PoolBlockVector->GetBlockCount() == 1)
@@ -13075,6 +13078,8 @@ VkResult VmaDefragmentationContext_T::DefragmentPassBegin(VmaDefragmentationPass
1307513078
{
1307613079
if (m_pBlockVectors[i] != VMA_NULL)
1307713080
{
13081+
VmaMutexLockWrite lock(m_pBlockVectors[i]->GetMutex(), m_pBlockVectors[i]->GetAllocator()->m_UseMutex);
13082+
1307813083
if (m_pBlockVectors[i]->GetBlockCount() > 1)
1307913084
{
1308013085
if (ComputeDefragmentation(*m_pBlockVectors[i], i))

0 commit comments

Comments
 (0)