Bladeren bron

don't try to evict mipchain-assets after the image has already been shutdown

Signed-off-by: Karl Haubenwallner <[email protected]>
Karl Haubenwallner 10 maanden geleden
bovenliggende
commit
c88dbcc97d

+ 2 - 0
Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Image/StreamingImage.h

@@ -164,6 +164,8 @@ namespace AZ
             // Uploads the mip chain content from the asset to the GPU
             RHI::ResultCode UploadMipChain(size_t mipChainIndex);
 
+            AZStd::mutex m_mipChainMutex;
+
             struct MipChainState
             {
                 static const uint16_t InvalidMipChain = (uint16_t)-1;

+ 9 - 0
Gems/Atom/RPI/Code/Source/RPI.Public/Image/StreamingImage.cpp

@@ -223,6 +223,8 @@ namespace AZ
 
                 GetRHIImage()->Shutdown();
 
+                // make sure we aren't iterrupting an active upload-callback
+                AZStd::scoped_lock<AZStd::mutex> guard(m_mipChainMutex);
                 // Evict all active mip chains
                 for (size_t mipChainIndex = 0; mipChainIndex < m_mipChains.size(); ++mipChainIndex)
                 {
@@ -400,6 +402,11 @@ namespace AZ
 
         void StreamingImage::EvictMipChainAsset(size_t mipChainIndex)
         {
+            if (m_mipChains.empty())
+            {
+                // it's possible we get here from a callback after the image was already destroyed
+                return;
+            }
             AZ_Assert(mipChainIndex < m_mipChains.size(), "Exceeded total number of mip chains.");
 
             const uint16_t mipChainBit = static_cast<uint16_t>(1 << mipChainIndex);
@@ -495,6 +502,8 @@ namespace AZ
 #ifdef AZ_RPI_STREAMING_IMAGE_DEBUG_LOG
                     AZ_TracePrintf("StreamingImage", "Upload mipchain done [%s]\n", mipChainAsset.GetHint().c_str());
 #endif
+                    // make sure the callback isn't interrupted by Shutdown(), which could remove mipchains mid-processing
+                    AZStd::scoped_lock<AZStd::mutex> guard(m_mipChainMutex);
                     EvictMipChainAsset(mipChainIndex); 
                 };