vulkan: avoid potential memory leaks if love.graphics.present errors.

This commit is contained in:
Sasha Szpakowski
2026-08-01 17:54:51 -03:00
parent 13db7bb5d5
commit 3a23b3607a
2 changed files with 7 additions and 8 deletions
+6 -7
View File
@@ -393,7 +393,7 @@ void Graphics::discard(const std::vector<bool> &colorbuffers, bool depthstencil)
startRenderPass();
}
image::ImageData *Graphics::submitGpuCommands(SubmitMode submitMode)
StrongRef<image::ImageData> 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<image::ImageData> 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<image::ImageData> 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();
}
}
+1 -1
View File
@@ -282,7 +282,7 @@ public:
VkCommandBuffer getCommandBufferForDataTransfer();
void queueCleanUp(std::function<void()> cleanUp);
void addReadbackCallback(std::function<void()> callback);
image::ImageData *submitGpuCommands(SubmitMode);
StrongRef<image::ImageData> submitGpuCommands(SubmitMode);
VkSampler getCachedSampler(const SamplerState &sampler);
SharedDescriptorPools *acquireDescriptorPools(int dynamicUniformBuffers, int sampledTextures, int storageTextures, int texelBuffers, int storageBuffers);
void releaseDescriptorPools(SharedDescriptorPools *pools);