From d59e17b105f65ba63deddae5affc8cc1f51d7a48 Mon Sep 17 00:00:00 2001 From: Exzap <13877693+Exzap@users.noreply.github.com> Date: Thu, 5 Dec 2024 12:33:21 +0100 Subject: [PATCH] Properly handle resource clean up --- src/Cafe/HW/Latte/Renderer/Vulkan/VKRMemoryManager.cpp | 8 +++++--- src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/VKRMemoryManager.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/VKRMemoryManager.cpp index 33af3651..3494dbc5 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/VKRMemoryManager.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/VKRMemoryManager.cpp @@ -334,10 +334,12 @@ VKRBuffer* VKRBuffer::Create(VKR_BUFFER_TYPE bufferType, size_t bufferSize, VkMe VKRBuffer::~VKRBuffer() { - if(m_mappedMemory) + if (m_mappedMemory) vkUnmapMemory(VulkanRenderer::GetInstance()->GetLogicalDevice(), m_bufferMemory); - vkFreeMemory(VulkanRenderer::GetInstance()->GetLogicalDevice(), m_bufferMemory, nullptr); - vkDestroyBuffer(VulkanRenderer::GetInstance()->GetLogicalDevice(), m_buffer, nullptr); + if (m_bufferMemory != VK_NULL_HANDLE) + vkFreeMemory(VulkanRenderer::GetInstance()->GetLogicalDevice(), m_bufferMemory, nullptr); + if (m_buffer != VK_NULL_HANDLE) + vkDestroyBuffer(VulkanRenderer::GetInstance()->GetLogicalDevice(), m_buffer, nullptr); } VkBufferChunkedHeap::~VkBufferChunkedHeap() diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp index 20163987..58904791 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp @@ -679,6 +679,9 @@ VulkanRenderer::~VulkanRenderer() vkDestroyDebugUtilsMessengerEXT(m_instance, m_debugCallback, nullptr); } + // destroy memory manager + delete memoryManager; + // destroy instance, devices if (m_instance != VK_NULL_HANDLE) { @@ -690,9 +693,6 @@ VulkanRenderer::~VulkanRenderer() vkDestroyInstance(m_instance, nullptr); } - // destroy memory manager - delete memoryManager; - // crashes? //glslang::FinalizeProcess(); }