Metal: fix null pointer use in LatteTextureViewMtl destructor

std::map::operator[] inserts a default-constructed (null) value when
the key is absent. In GetSwizzledView, m_fallbackViewCache[key] would
insert a null entry, but if a free slot existed in m_viewCache the
texture was stored there instead, leaving the null entry in
m_fallbackViewCache. The destructor then iterated the map and called
->release() on that null pointer.
This commit is contained in:
Fabio Arnold 2026-03-29 15:32:28 +02:00
parent 9ad8b44b52
commit 555469974c

View File

@ -104,17 +104,17 @@ MTL::Texture* LatteTextureViewMtl::GetSwizzledView(uint32 gpuSamplerSwizzle)
}
// Fallback cache
auto& fallbackEntry = m_fallbackViewCache[gpuSamplerSwizzle];
if (fallbackEntry)
auto it = m_fallbackViewCache.find(gpuSamplerSwizzle);
if (it != m_fallbackViewCache.end())
{
return fallbackEntry;
return it->second;
}
MTL::Texture* texture = CreateSwizzledView(gpuSamplerSwizzle);
if (freeIndex != -1)
m_viewCache[freeIndex] = {gpuSamplerSwizzle, texture};
else
fallbackEntry = texture;
m_fallbackViewCache[gpuSamplerSwizzle] = texture;
return texture;
}