GS/HW: Fix crash with custom textures

This commit is contained in:
Stenzek 2023-12-31 16:17:34 +10:00 committed by Connor McLaughlin
parent 47f372f215
commit 3a72b3fe3f
2 changed files with 11 additions and 0 deletions

View File

@ -6076,6 +6076,15 @@ void GSTextureCache::SourceMap::Add(Source* s, const GIFRegTEX0& TEX0)
});
}
void GSTextureCache::SourceMap::SwapTexture(GSTexture* old_tex, GSTexture* new_tex)
{
for (auto s : m_surfaces)
{
if (s->m_texture == old_tex)
s->m_texture = new_tex;
}
}
void GSTextureCache::SourceMap::RemoveAll()
{
for (auto s : m_surfaces)
@ -6358,6 +6367,7 @@ void GSTextureCache::InjectHashCacheTexture(const HashCacheKey& key, GSTexture*
m_hash_cache_replacement_memory_usage -= it->second.texture->GetMemUsage();
it->second.is_replacement = true;
m_src.SwapTexture(it->second.texture, tex);
g_gs_device->Recycle(it->second.texture);
it->second.texture = tex;
}

View File

@ -339,6 +339,7 @@ public:
std::array<FastList<Source*>, MAX_PAGES> m_map;
void Add(Source* s, const GIFRegTEX0& TEX0);
void SwapTexture(GSTexture* old_tex, GSTexture* new_tex);
void RemoveAll();
void RemoveAt(Source* s);
};