diff --git a/projects/mtg/include/WCachedResource.h b/projects/mtg/include/WCachedResource.h index 6f185336d..01211bc6c 100644 --- a/projects/mtg/include/WCachedResource.h +++ b/projects/mtg/include/WCachedResource.h @@ -66,6 +66,7 @@ public: void Refresh(); unsigned long size(); bool isGood(); + bool isLocked(); //Is the resource locked? bool Attempt(string filename, int submode, int & error); bool compare(JTexture * t) {return (t == texture);}; JTexture * Actual(); //Return this texture as is. Does not make a new one. diff --git a/projects/mtg/src/WCachedResource.cpp b/projects/mtg/src/WCachedResource.cpp index c1d72601e..e0f37b652 100644 --- a/projects/mtg/src/WCachedResource.cpp +++ b/projects/mtg/src/WCachedResource.cpp @@ -84,6 +84,18 @@ WCachedTexture::~WCachedTexture(){ JTexture * WCachedTexture::Actual(){ return texture; } +bool WCachedTexture::isLocked(){ + if(locks != WRES_UNLOCKED) + return true; + + for(vector::iterator it=trackedQuads.begin();it!=trackedQuads.end();it++){ + if((*it)->isLocked()) + return true; + } + + return false; +} + bool WCachedTexture::ReleaseQuad(JQuad* quad){ if(quad == NULL) return false; diff --git a/projects/mtg/src/WResourceManager.cpp b/projects/mtg/src/WResourceManager.cpp index fff2beaab..2e704b5b1 100644 --- a/projects/mtg/src/WResourceManager.cpp +++ b/projects/mtg/src/WResourceManager.cpp @@ -333,7 +333,25 @@ void WResourceManager::Release(JTexture * tex){ if(!tex) return; - textureWCache.Release(tex); + //Copied direct from WCache::Release(). This is quick and dirty. + map::iterator it; + for(it=textureWCache.cache.begin();it!=textureWCache.cache.end();it++){ + if(it->second && it->second->compare(tex)) + break; + } + + if(it == textureWCache.cache.end()) + return; //Not here, can't release. + + if(it->second){ + it->second->unlock(); //Release one lock. + if(it->second->locks != WRES_UNLOCKED) //Normally we'd call isLocked, but this way ignores quads. + return; //Locked + } + + textureWCache.Delete(it->second); + textureWCache.cache.erase(it); + return; //Released! } void WResourceManager::Unmiss(string filename){ @@ -977,6 +995,7 @@ cacheItem * WCache::Retrieve(int id, string filename, in } //Something went wrong. RemoveItem(tc); + mError = CACHE_ERROR_BAD; } //Record managed failure. Cache failure is recorded in Get(). @@ -1030,7 +1049,8 @@ cacheItem * WCache::Get(int id, string filename, int sty it = cache.find(lookup); //Well, we've found something... if(it != cache.end()){ - mError = CACHE_ERROR_NONE; //We found an entry in cache, so not an error. + if(!it->second) + mError = CACHE_ERROR_404; return it->second; //A hit, or maybe a miss. } }