Properly handle resource clean up

This commit is contained in:
Exzap 2024-12-05 12:33:21 +01:00
parent e97493b2a1
commit d59e17b105
2 changed files with 8 additions and 6 deletions

View File

@ -334,10 +334,12 @@ VKRBuffer* VKRBuffer::Create(VKR_BUFFER_TYPE bufferType, size_t bufferSize, VkMe
VKRBuffer::~VKRBuffer() VKRBuffer::~VKRBuffer()
{ {
if(m_mappedMemory) if (m_mappedMemory)
vkUnmapMemory(VulkanRenderer::GetInstance()->GetLogicalDevice(), m_bufferMemory); vkUnmapMemory(VulkanRenderer::GetInstance()->GetLogicalDevice(), m_bufferMemory);
vkFreeMemory(VulkanRenderer::GetInstance()->GetLogicalDevice(), m_bufferMemory, nullptr); if (m_bufferMemory != VK_NULL_HANDLE)
vkDestroyBuffer(VulkanRenderer::GetInstance()->GetLogicalDevice(), m_buffer, nullptr); vkFreeMemory(VulkanRenderer::GetInstance()->GetLogicalDevice(), m_bufferMemory, nullptr);
if (m_buffer != VK_NULL_HANDLE)
vkDestroyBuffer(VulkanRenderer::GetInstance()->GetLogicalDevice(), m_buffer, nullptr);
} }
VkBufferChunkedHeap::~VkBufferChunkedHeap() VkBufferChunkedHeap::~VkBufferChunkedHeap()

View File

@ -679,6 +679,9 @@ VulkanRenderer::~VulkanRenderer()
vkDestroyDebugUtilsMessengerEXT(m_instance, m_debugCallback, nullptr); vkDestroyDebugUtilsMessengerEXT(m_instance, m_debugCallback, nullptr);
} }
// destroy memory manager
delete memoryManager;
// destroy instance, devices // destroy instance, devices
if (m_instance != VK_NULL_HANDLE) if (m_instance != VK_NULL_HANDLE)
{ {
@ -690,9 +693,6 @@ VulkanRenderer::~VulkanRenderer()
vkDestroyInstance(m_instance, nullptr); vkDestroyInstance(m_instance, nullptr);
} }
// destroy memory manager
delete memoryManager;
// crashes? // crashes?
//glslang::FinalizeProcess(); //glslang::FinalizeProcess();
} }