From 4efe05799543f96740f5a3559c1ba1eeec944839 Mon Sep 17 00:00:00 2001 From: "Matias N. Goldberg" Date: Tue, 12 Sep 2023 19:52:32 -0300 Subject: [PATCH] [Vk] Fix dangling pointer after destroying TextureGpu (#416) Fixes #416 --- RenderSystems/Vulkan/src/OgreVulkanQueue.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/RenderSystems/Vulkan/src/OgreVulkanQueue.cpp b/RenderSystems/Vulkan/src/OgreVulkanQueue.cpp index 5f640d7db30..592460c41b9 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanQueue.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanQueue.cpp @@ -1051,10 +1051,14 @@ namespace Ogre if( mEncoderState == EncoderCopyOpen ) { bool needsToFlush = false; + bool mustRemoveFromBarrier = false; TextureGpuDownloadMap::const_iterator itor = mCopyDownloadTextures.find( texture ); if( itor != mCopyDownloadTextures.end() ) + { needsToFlush = true; + mustRemoveFromBarrier = true; + } else { FastArray::const_iterator it2 = @@ -1072,6 +1076,14 @@ namespace Ogre OGRE_ASSERT_LOW( texture->mCurrLayout == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL || texture->mCurrLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL ); endCopyEncoder(); + + if( mustRemoveFromBarrier ) + { + // endCopyEncoder() just called solver.assumeTransition() on this texture + // but we're destroying the texture. Remove the dangling pointer. + BarrierSolver &solver = mRenderSystem->getBarrierSolver(); + solver.textureDeleted( texture ); + } } } }