diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/resources/resourcemanager.cpp | 28 | ||||
-rw-r--r-- | src/resources/resourcemanager.h | 6 |
2 files changed, 33 insertions, 1 deletions
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index aae5c3db7..7d80e8bcc 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -67,6 +67,7 @@ ResourceManager::~ResourceManager() { mDestruction = true; mResources.insert(mOrphanedResources.begin(), mOrphanedResources.end()); + mResources.insert(mDeletedResources.begin(), mDeletedResources.end()); // Release any remaining spritedefs first because they depend on image sets ResourceIterator iter = mResources.begin(); @@ -671,7 +672,16 @@ void ResourceManager::release(Resource *const res) if (!res || mDestruction) return; - const ResourceIterator resIter = mResources.find(res->mIdPath); + ResourceIterator resIter = mDeletedResources.find(res->mIdPath); + if (resIter != mDeletedResources.end() && resIter->second == res) + { + // we found zero counted image in deleted list. deleting it and exit. + mDeletedResources.erase(resIter); + delete res; + return; + } + + resIter = mResources.find(res->mIdPath); // The resource has to exist assert(resIter != mResources.end() && resIter->second == res); @@ -691,6 +701,22 @@ void ResourceManager::release(Resource *const res) #endif } +void ResourceManager::moveToDeleted(Resource *const res) +{ + ResourceIterator resIter = mResources.find(res->mIdPath); + if (resIter != mResources.end() && resIter->second == res) + { + mDeletedResources.insert(*resIter); + mResources.erase(resIter); + } + resIter = mOrphanedResources.find(res->mIdPath); + if (resIter != mOrphanedResources.end() && resIter->second == res) + { + mDeletedResources.insert(*resIter); + mOrphanedResources.erase(resIter); + } +} + ResourceManager *ResourceManager::getInstance() { // Create a new instance if necessary. diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index 7ed510ac4..2c9fbe3eb 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -224,6 +224,11 @@ class ResourceManager final void release(Resource *const res); /** + * Move resource to deleted resources list. + */ + void moveToDeleted(Resource *const res); + + /** * Allocates data into a buffer pointer for raw data loading. The * returned data is expected to be freed using <code>free()</code>. * @@ -307,6 +312,7 @@ class ResourceManager final std::set<SDL_Surface*> deletedSurfaces; Resources mResources; Resources mOrphanedResources; + Resources mDeletedResources; time_t mOldestOrphan; std::string mSelectedSkin; std::string mSkinName; |