From c5327bfc4f607dceb1a3558c5052a65eef36884a Mon Sep 17 00:00:00 2001 From: niki Date: Mon, 11 Jul 2022 01:47:34 +0200 Subject: [PATCH] vulkan: fix some more memory leaks --- src/modules/graphics/vulkan/Graphics.cpp | 10 +++++----- src/modules/graphics/vulkan/Graphics.h | 4 ++-- src/modules/graphics/vulkan/ShaderStage.cpp | 2 ++ src/modules/graphics/vulkan/Texture.cpp | 2 ++ 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/modules/graphics/vulkan/Graphics.cpp b/src/modules/graphics/vulkan/Graphics.cpp index bfd00a7d9..07cc95734 100644 --- a/src/modules/graphics/vulkan/Graphics.cpp +++ b/src/modules/graphics/vulkan/Graphics.cpp @@ -1181,7 +1181,7 @@ namespace love { } if (texture == nullptr) { - setTexture(standardTexture); + setTexture(standardTexture.get()); } else { setTexture(texture); @@ -1402,7 +1402,7 @@ namespace love { void Graphics::createDefaultTexture() { Texture::Settings settings; - standardTexture = newTexture(settings); + standardTexture.reset((Texture*)newTexture(settings)); } void Graphics::createQuadIndexBuffer() { @@ -1410,7 +1410,7 @@ namespace love { return; size_t size = sizeof(uint16) * getIndexCount(TRIANGLEINDEX_QUADS, LOVE_UINT16_MAX); - quadIndexBuffer = static_cast(newStreamBuffer(BUFFERUSAGE_INDEX, size)); + quadIndexBuffer.reset((StreamBuffer*)newStreamBuffer(BUFFERUSAGE_INDEX, size)); auto map = quadIndexBuffer->map(size); fillIndices(TRIANGLEINDEX_QUADS, 0, LOVE_UINT16_MAX, (uint16*)map.data); quadIndexBuffer->unmap(size); @@ -1460,14 +1460,13 @@ namespace love { cleanupSwapChain(); + batchedDrawBuffers.clear(); for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) { vkDestroySemaphore(device, renderFinishedSemaphores[i], nullptr); vkDestroySemaphore(device, imageAvailableSemaphores[i], nullptr); vkDestroyFence(device, inFlightFences[i], nullptr); } - vkDestroyDescriptorPool(device, descriptorPool, nullptr); - vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr); vkDestroyCommandPool(device, commandPool, nullptr); vkDestroyDevice(device, nullptr); @@ -1478,6 +1477,7 @@ namespace love { void Graphics::cleanupSwapChain() { std::cout << "cleanupSwapChain "; + vkDestroyDescriptorPool(device, descriptorPool, nullptr); for (size_t i = 0; i < swapChainFramBuffers.size(); i++) { vkDestroyFramebuffer(device, swapChainFramBuffers[i], nullptr); } diff --git a/src/modules/graphics/vulkan/Graphics.h b/src/modules/graphics/vulkan/Graphics.h index 91668f6d8..820e7e797 100644 --- a/src/modules/graphics/vulkan/Graphics.h +++ b/src/modules/graphics/vulkan/Graphics.h @@ -204,11 +204,11 @@ namespace love { uint32_t imageIndex = 0; bool framebufferResized = false; VmaAllocator vmaAllocator = VK_NULL_HANDLE; - graphics::Texture* standardTexture = nullptr; + std::unique_ptr standardTexture = nullptr; + std::unique_ptr quadIndexBuffer = nullptr; // we need an array of draw buffers, since the frames are being rendered asynchronously // and we can't (or shouldn't) update the contents of the buffers while they're still in flight / being rendered. std::vector batchedDrawBuffers; - StreamBuffer* quadIndexBuffer = nullptr; graphics::Texture* currentTexture = nullptr; std::vector> uniformBufferMap; std::vector>> descriptorSetsMap; diff --git a/src/modules/graphics/vulkan/ShaderStage.cpp b/src/modules/graphics/vulkan/ShaderStage.cpp index bcce9d5c0..fe9489b18 100644 --- a/src/modules/graphics/vulkan/ShaderStage.cpp +++ b/src/modules/graphics/vulkan/ShaderStage.cpp @@ -205,6 +205,8 @@ namespace love { if (vkCreateShaderModule(device, &createInfo, nullptr, &shaderModule) != VK_SUCCESS) { throw love::Exception("failed to create shader module"); } + + return true; } void ShaderStage::unloadVolatile() { diff --git a/src/modules/graphics/vulkan/Texture.cpp b/src/modules/graphics/vulkan/Texture.cpp index 74eae5c9b..a67149ccc 100644 --- a/src/modules/graphics/vulkan/Texture.cpp +++ b/src/modules/graphics/vulkan/Texture.cpp @@ -61,6 +61,8 @@ namespace love { } createTextureImageView(); createTextureSampler(); + + return true; } void Texture::unloadVolatile() {