From dbe3662bfc89c28748a32218f5fdbcfc543ba105 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 1 Mar 2018 07:29:05 +0100 Subject: [PATCH] [dxvk] Fixed potential memory allocation issue --- src/dxvk/dxvk_memory.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/dxvk/dxvk_memory.cpp b/src/dxvk/dxvk_memory.cpp index 6a9f5a32..821a9565 100644 --- a/src/dxvk/dxvk_memory.cpp +++ b/src/dxvk/dxvk_memory.cpp @@ -162,9 +162,12 @@ namespace dxvk { // chunks since that might lead to severe fragmentation. if (size >= (m_chunkSize / 4)) { VkDeviceMemory memory = this->allocDeviceMemory(size); - void* mapPtr = this->mapDeviceMemory(memory); - return DxvkMemory(nullptr, this, memory, 0, size, mapPtr); + if (memory == VK_NULL_HANDLE) + return DxvkMemory(); + + return DxvkMemory(nullptr, this, memory, + 0, size, this->mapDeviceMemory(memory)); } else { std::lock_guard lock(m_mutex); @@ -179,10 +182,12 @@ namespace dxvk { // None of the existing chunks could satisfy // the request, we need to create a new one VkDeviceMemory chunkMem = this->allocDeviceMemory(m_chunkSize); - void* chunkPtr = this->mapDeviceMemory(chunkMem); - Rc newChunk = new DxvkMemoryChunk( - this, chunkMem, chunkPtr, m_chunkSize); + if (chunkMem == VK_NULL_HANDLE) + return DxvkMemory(); + + Rc newChunk = new DxvkMemoryChunk(this, + chunkMem, this->mapDeviceMemory(chunkMem), m_chunkSize); DxvkMemory memory = newChunk->alloc(size, align); m_chunks.push_back(std::move(newChunk));