From 7d5f3084949cb642b4cbf595151824180f630cd5 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 26 Mar 2016 12:17:28 -0700 Subject: [PATCH] Fix a crash where we used an old framebuf. This was causing Breath of Fire 3 to crash, because it had an offset framebuffer set that was never detatched. --- GPU/Common/TextureCacheCommon.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index fb5bb17fb3..c28b896743 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -178,16 +178,16 @@ void TextureCacheCommon::NotifyFramebuffer(u32 address, VirtualFramebuffer *fram break; case NOTIFY_FB_DESTROYED: - fbCache_.erase(std::remove(fbCache_.begin(), fbCache_.end(), framebuffer), fbCache_.end()); - for (auto it = cache.lower_bound(cacheKey), end = cache.upper_bound(cacheKeyEnd); it != end; ++it) { - DetachFramebuffer(&it->second, addr, framebuffer); - } - for (auto it = cache.lower_bound(mirrorCacheKey), end = cache.upper_bound(mirrorCacheKeyEnd); it != end; ++it) { - const u64 mirrorlessKey = it->first & ~0x0060000000000000ULL; - // Let's still make sure it's in the cache range. - if (mirrorlessKey >= cacheKey && mirrorlessKey <= cacheKeyEnd) { - DetachFramebuffer(&it->second, addr, framebuffer); - } + fbCache_.erase(std::remove(fbCache_.begin(), fbCache_.end(), framebuffer), fbCache_.end()); + + // We may have an offset texture attached. So we use fbTexInfo as a guide. + // We're not likely to have many attached framebuffers. + for (auto it = fbTexInfo_.begin(); it != fbTexInfo_.end(); ) { + u64 cachekey = it->first; + // We might erase, so move to the next one already (which won't become invalid.) + ++it; + + DetachFramebuffer(&cache[cachekey], addr, framebuffer); } break; }