From 55c65fb8a2491ffab6dd4aba0e77248744f1f2d4 Mon Sep 17 00:00:00 2001 From: rafadevai Date: Mon, 18 Aug 2025 10:57:46 -0700 Subject: [PATCH] VK: Fix memory corruption in VulkanExternalImageManager (#9116) When calling setExternalSamplerVkSet the recycle function lambda captured some variables allocated on the stack, which are out of scope by the time the function is called. Change the capture to be done by value instead of by ref to avoid this problem. --- .../backend/src/vulkan/VulkanExternalImageManager.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/filament/backend/src/vulkan/VulkanExternalImageManager.cpp b/filament/backend/src/vulkan/VulkanExternalImageManager.cpp index 8b1294d56a..05ace43cba 100644 --- a/filament/backend/src/vulkan/VulkanExternalImageManager.cpp +++ b/filament/backend/src/vulkan/VulkanExternalImageManager.cpp @@ -191,9 +191,11 @@ void VulkanExternalImageManager::updateSetAndLayout( VkDescriptorSet const srcSet = oldSet != VK_NULL_HANDLE ? oldSet : set->getVkSet(); copySet(mPlatform->getDevice(), srcSet, newSet, copyBindings); - set->setExternalSamplerVkSet(newSet, [&](VulkanDescriptorSet*) { - mDescriptorSetCache->manualRecycle(layout->count, newLayout, newSet); - }); + set->setExternalSamplerVkSet(newSet, + [&descriptorSetCache = mDescriptorSetCache, layoutCount = layout->count, newLayout, + newSet](VulkanDescriptorSet*) { + descriptorSetCache->manualRecycle(layoutCount, newLayout, newSet); + }); if (oldLayout != newLayout) { layout->setExternalSamplerVkLayout(newLayout); }