From e9d115a8b178b851b14b35e356437afe1ccc59af Mon Sep 17 00:00:00 2001 From: nodchip Date: Fri, 22 Oct 2010 03:50:44 +0000 Subject: [PATCH] VideoCommon: Fixed the crash when the code cache of DLCache is full. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6299 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/VideoCommon/Src/DLCache.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Source/Core/VideoCommon/Src/DLCache.cpp b/Source/Core/VideoCommon/Src/DLCache.cpp index 0e146ebccf..23895e050e 100644 --- a/Source/Core/VideoCommon/Src/DLCache.cpp +++ b/Source/Core/VideoCommon/Src/DLCache.cpp @@ -40,6 +40,7 @@ #include "VideoConfig.h" #define DL_CODE_CACHE_SIZE (1024*1024*16) +#define DL_CODE_CLEAR_THRESHOLD (256 * 1024) extern int frameCount; using namespace Gen; @@ -605,6 +606,11 @@ void ProgressiveCleanup() } } +static size_t GetSpaceLeft() +{ + return DL_CODE_CACHE_SIZE - (emitter.GetCodePtr() - dlcode_cache); +} + } // namespace // NOTE - outside the namespace on purpose. @@ -614,6 +620,12 @@ bool HandleDisplayList(u32 address, u32 size) if(!g_ActiveConfig.bDlistCachingEnable) return false; if(size == 0) return false; + + // Is this thread safe? + if (DLCache::GetSpaceLeft() < DL_CODE_CLEAR_THRESHOLD) { + DLCache::Clear(); + } + u64 dl_id = DLCache::CreateMapId(address, size); DLCache::DLMap::iterator iter = DLCache::dl_map.find(dl_id);