From 8e13d53b1e552d6b939737689b5d5128c1a33d10 Mon Sep 17 00:00:00 2001 From: Powei Feng Date: Mon, 11 Sep 2023 23:21:52 -0700 Subject: [PATCH] vulkan: fix swapchain leak (#7161) --- filament/backend/src/vulkan/VulkanDriver.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/filament/backend/src/vulkan/VulkanDriver.cpp b/filament/backend/src/vulkan/VulkanDriver.cpp index 3145d5df4a6..875a5837362 100644 --- a/filament/backend/src/vulkan/VulkanDriver.cpp +++ b/filament/backend/src/vulkan/VulkanDriver.cpp @@ -526,21 +526,22 @@ void VulkanDriver::createSwapChainR(Handle sch, void* nativeWindow, << utils::io::endl; flags = flags | ~(backend::SWAP_CHAIN_CONFIG_SRGB_COLORSPACE); } - mResourceAllocator.construct(sch, mPlatform, mContext, mAllocator, - mCommands.get(), mStagePool, nativeWindow, flags); + auto swapChain = mResourceAllocator.construct(sch, mPlatform, mContext, + mAllocator, mCommands.get(), mStagePool, nativeWindow, flags); + mResourceManager.acquire(swapChain); } void VulkanDriver::createSwapChainHeadlessR(Handle sch, uint32_t width, uint32_t height, uint64_t flags) { - if ((flags & backend::SWAP_CHAIN_CONFIG_SRGB_COLORSPACE) != 0 && - !isSRGBSwapChainSupported()) { + if ((flags & backend::SWAP_CHAIN_CONFIG_SRGB_COLORSPACE) != 0 && !isSRGBSwapChainSupported()) { utils::slog.w << "sRGB swapchain requested, but Platform does not support it" << utils::io::endl; flags = flags | ~(backend::SWAP_CHAIN_CONFIG_SRGB_COLORSPACE); } assert_invariant(width > 0 && height > 0 && "Vulkan requires non-zero swap chain dimensions."); - mResourceAllocator.construct(sch, mPlatform, mContext, mAllocator, - mCommands.get(), mStagePool, nullptr, flags, VkExtent2D{width, height}); + auto swapChain = mResourceAllocator.construct(sch, mPlatform, mContext, + mAllocator, mCommands.get(), mStagePool, nullptr, flags, VkExtent2D{width, height}); + mResourceManager.acquire(swapChain); } void VulkanDriver::createTimerQueryR(Handle tqh, int) {