diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-09-30 04:19:58 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-09-30 04:19:58 +0300 |
commit | 2c9fbdd6e9579549735eeb4cdfd83eef7e4ec55e (patch) | |
tree | 2f4c69c11a0a614c77bfa2bfa9a9294a1db89eb9 /src/resources | |
parent | 48a21f6542e799e41735febbda76815e058954ac (diff) | |
download | manaverse-2c9fbdd6e9579549735eeb4cdfd83eef7e4ec55e.tar.gz manaverse-2c9fbdd6e9579549735eeb4cdfd83eef7e4ec55e.tar.bz2 manaverse-2c9fbdd6e9579549735eeb4cdfd83eef7e4ec55e.tar.xz manaverse-2c9fbdd6e9579549735eeb4cdfd83eef7e4ec55e.zip |
Dump in resource list also ref count.
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/resourcemanager.cpp | 91 | ||||
-rw-r--r-- | src/resources/resourcemanager.h | 4 |
2 files changed, 70 insertions, 25 deletions
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 9beba49e7..2bc269503 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -161,6 +161,7 @@ ResourceManager::~ResourceManager() ++iter; } } + clearDeleted(); clearScheduled(); } @@ -214,31 +215,7 @@ bool ResourceManager::cleanOrphans(const bool always) } else { -#ifdef USE_OPENGL - const Image *const image = dynamic_cast<Image*>(res); - if (image) - { - const std::string src = image->getSource(); - if (image && image->getGLImage()) - { - logger->log("ResourceManager::release(%s, %u) %s", - res->mIdPath.c_str(), image->getGLImage(), - src.c_str()); - } - else - { - logger->log("ResourceManager::release(%s) %s", - res->mIdPath.c_str(), src.c_str()); - } - } - else - { - logger->log("ResourceManager::release(%s)", - res->mIdPath.c_str()); - } -#else - logger->log("ResourceManager::release(%s)", res->mIdPath.c_str()); -#endif + logResource(res); const ResourceIterator toErase = iter; ++iter; mOrphanedResources.erase(toErase); @@ -252,6 +229,70 @@ bool ResourceManager::cleanOrphans(const bool always) return status; } +void ResourceManager::logResource(const Resource *const res) +{ +#ifdef USE_OPENGL + const Image *const image = dynamic_cast<const Image *const>(res); + if (image) + { + std::string src = image->getSource(); + const int count = image->getRefCount(); + if (count) + src += " " + toString(count); + if (image && image->getGLImage()) + { + logger->log("ResourceManager::release(%s, %u) %s", + res->mIdPath.c_str(), image->getGLImage(), + src.c_str()); + } + else + { + logger->log("ResourceManager::release(%s) %s", + res->mIdPath.c_str(), src.c_str()); + } + } + else + { + logger->log("ResourceManager::release(%s)", + res->mIdPath.c_str()); + } +#else + logger->log("ResourceManager::release(%s)", res->mIdPath.c_str()); +#endif +} + +void ResourceManager::clearDeleted() +{ + bool status(true); + logger->log("clear deleted"); + while (status) + { + status = false; + std::set<Resource*>::iterator resDelIter = mDeletedResources.begin(); + while (resDelIter != mDeletedResources.end()) + { + if (!(*resDelIter)->getRefCount()) + { + status = true; + logResource(*resDelIter); + mDeletedResources.erase(resDelIter); + delete *resDelIter; + break; + } + ++ resDelIter; + } + } + if (!mDeletedResources.empty()) + { + logger->log("leaks in deleted"); + std::set<Resource*>::iterator resDelIter = mDeletedResources.begin(); + while (resDelIter != mDeletedResources.end()) + { + logResource(*resDelIter); + ++ resDelIter; + } + } +} bool ResourceManager::setWriteDir(const std::string &path) const { return static_cast<bool>(PHYSFS_setWriteDir(path.c_str())); diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index 6c089a243..5699fc7fc 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -225,6 +225,10 @@ class ResourceManager final */ void release(Resource *const res); + void clearDeleted(); + + static void logResource(const Resource *const res); + /** * Move resource to deleted resources list. */ |