summaryrefslogtreecommitdiff
path: root/src/resources/resourcemanager.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-09-30 15:47:51 +0300
committerAndrei Karas <akaras@inbox.ru>2012-09-30 19:38:07 +0300
commit8b984259c0d7d7af5394defc89a3b64d7b479425 (patch)
treef67aef7fc0ffb2fb0d54dc042b49bb33805a4a0e /src/resources/resourcemanager.cpp
parent2c9fbdd6e9579549735eeb4cdfd83eef7e4ec55e (diff)
downloadplus-8b984259c0d7d7af5394defc89a3b64d7b479425.tar.gz
plus-8b984259c0d7d7af5394defc89a3b64d7b479425.tar.bz2
plus-8b984259c0d7d7af5394defc89a3b64d7b479425.tar.xz
plus-8b984259c0d7d7af5394defc89a3b64d7b479425.zip
Some fixes in atlases deletion.
Diffstat (limited to 'src/resources/resourcemanager.cpp')
-rw-r--r--src/resources/resourcemanager.cpp47
1 files changed, 41 insertions, 6 deletions
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 2bc269503..e479a9609 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -289,6 +289,11 @@ void ResourceManager::clearDeleted()
while (resDelIter != mDeletedResources.end())
{
logResource(*resDelIter);
+
+ // for debug only
+// delete *resDelIter;
+ // for debug only
+
++ resDelIter;
}
}
@@ -446,6 +451,18 @@ bool ResourceManager::isInCache(const std::string &idPath) const
return (resIter != mResources.end() && resIter->second);
}
+Resource *ResourceManager::getTempResource(const std::string &idPath)
+{
+ const ResourceCIterator &resIter = mResources.find(idPath);
+ if (resIter != mResources.end())
+ {
+ Resource *const res = resIter->second;
+ if (resIter->second)
+ return res;
+ }
+ return nullptr;
+}
+
Resource *ResourceManager::getFromCache(const std::string &idPath)
{
// Check if the id exists, and return the value if it does.
@@ -714,7 +731,7 @@ struct AtlasLoader
const AtlasLoader *const rl = static_cast<const AtlasLoader *const>(v);
AtlasResource *const resource = AtlasManager::loadTextureAtlas(
rl->name, *rl->files);
- AtlasManager::injectToResources(resource);
+// AtlasManager::injectToResources(resource);
return resource;
}
};
@@ -788,17 +805,35 @@ void ResourceManager::release(Resource *const res)
void ResourceManager::moveToDeleted(Resource *const res)
{
+ if (!res)
+ return;
+
+ bool found(false);
+ const int count = res->getRefCount();
+ if (count == 1)
+ logResource(res);
+ res->decRef();
ResourceIterator resIter = mResources.find(res->mIdPath);
if (resIter != mResources.end() && resIter->second == res)
{
- mDeletedResources.insert(res);
mResources.erase(resIter);
+ found = true;
}
- resIter = mOrphanedResources.find(res->mIdPath);
- if (resIter != mOrphanedResources.end() && resIter->second == res)
+ else
{
- mDeletedResources.insert(res);
- mOrphanedResources.erase(resIter);
+ resIter = mOrphanedResources.find(res->mIdPath);
+ if (resIter != mOrphanedResources.end() && resIter->second == res)
+ {
+ mOrphanedResources.erase(resIter);
+ found = true;
+ }
+ }
+ if (found)
+ {
+ if (count > 1)
+ mDeletedResources.insert(res);
+ else
+ delete res;
}
}