From 3a23b3607a54c6fa2e1fc9bfaec5df26d8b3b9cb Mon Sep 17 00:00:00 2001 From: Sasha Szpakowski Date: Sat, 1 Aug 2026 17:54:51 -0300 Subject: [PATCH] vulkan: avoid potential memory leaks if love.graphics.present errors. --- src/modules/graphics/vulkan/Graphics.cpp | 13 ++++++------- src/modules/graphics/vulkan/Graphics.h | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/modules/graphics/vulkan/Graphics.cpp b/src/modules/graphics/vulkan/Graphics.cpp index 087fa958d..4c65fda87 100644 --- a/src/modules/graphics/vulkan/Graphics.cpp +++ b/src/modules/graphics/vulkan/Graphics.cpp @@ -393,7 +393,7 @@ void Graphics::discard(const std::vector &colorbuffers, bool depthstencil) startRenderPass(); } -image::ImageData *Graphics::submitGpuCommands(SubmitMode submitMode) +StrongRef Graphics::submitGpuCommands(SubmitMode submitMode) { flushBatchedDraws(); @@ -515,7 +515,7 @@ image::ImageData *Graphics::submitGpuCommands(SubmitMode submitMode) if (result != VK_SUCCESS) throw love::Exception("Failed to submit Vulkan draw command buffer: %s", Vulkan::getErrorString(result)); - image::ImageData *screenshotImageData = nullptr; + StrongRef screenshotImageData; if (submitMode == SUBMIT_NOPRESENT || submitMode == SUBMIT_RESTART || screenshotBuffer != VK_NULL_HANDLE) { @@ -534,11 +534,12 @@ image::ImageData *Graphics::submitGpuCommands(SubmitMode submitMode) try { - screenshotImageData = imageModule->newImageData( + screenshotImageData.set(imageModule->newImageData( swapChainExtent.width, swapChainExtent.height, PIXELFORMAT_RGBA8_UNORM, - screenshotAllocationInfo.pMappedData); + screenshotAllocationInfo.pMappedData), + Acquire::NORETAIN); } catch (love::Exception &) { @@ -595,7 +596,7 @@ void Graphics::present(void *screenshotCallbackdata) deprecations.draw(this); - image::ImageData *screenshotImageData = submitGpuCommands(SUBMIT_PRESENT); + StrongRef screenshotImageData = submitGpuCommands(SUBMIT_PRESENT); VkResult result = VK_SUCCESS; @@ -674,8 +675,6 @@ void Graphics::present(void *screenshotCallbackdata) info.callback(&info, screenshotImageData, screenshotCallbackdata); } pendingScreenshotCallbacks.clear(); - - screenshotImageData->release(); } } diff --git a/src/modules/graphics/vulkan/Graphics.h b/src/modules/graphics/vulkan/Graphics.h index 573db41da..49b371060 100644 --- a/src/modules/graphics/vulkan/Graphics.h +++ b/src/modules/graphics/vulkan/Graphics.h @@ -282,7 +282,7 @@ public: VkCommandBuffer getCommandBufferForDataTransfer(); void queueCleanUp(std::function cleanUp); void addReadbackCallback(std::function callback); - image::ImageData *submitGpuCommands(SubmitMode); + StrongRef submitGpuCommands(SubmitMode); VkSampler getCachedSampler(const SamplerState &sampler); SharedDescriptorPools *acquireDescriptorPools(int dynamicUniformBuffers, int sampledTextures, int storageTextures, int texelBuffers, int storageBuffers); void releaseDescriptorPools(SharedDescriptorPools *pools);