From ede06c1fe25184b1232687950ce79dc29352c00b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 29 Aug 2016 21:47:06 +0300 Subject: Add into resource manager better reports about leaks. --- src/resources/resourcemanager/resourcemanager.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/resources/resourcemanager') diff --git a/src/resources/resourcemanager/resourcemanager.cpp b/src/resources/resourcemanager/resourcemanager.cpp index 5ecc58732..b4e80d2c1 100644 --- a/src/resources/resourcemanager/resourcemanager.cpp +++ b/src/resources/resourcemanager/resourcemanager.cpp @@ -69,6 +69,7 @@ ResourceManager::~ResourceManager() ResourceIterator iter = mResources.begin(); #ifdef DEBUG_LEAKS + bool status(false); while (iter != mResources.end()) { if (iter->second) @@ -78,11 +79,17 @@ ResourceManager::~ResourceManager() logger->log(std::string("ResourceLeak: ").append( iter->second->getIdPath()).append(" (").append( toString(iter->second->getRefCount())).append(")")); + status = true; } } ++iter; } +#ifdef UNITTESTS + if (status) + reportAlways("Found leaked resources."); +#endif + iter = mResources.begin(); #endif @@ -269,7 +276,11 @@ void ResourceManager::logResource(const Resource *const res) } else { - logger->log("resource(%s)", res->mIdPath.c_str()); + std::string src = res->getSource(); + const int count = res->getRefCount(); + if (count > 0) + src.append(" ").append(toString(count)); + logger->log("resource(%s) %s", res->mIdPath.c_str(), src.c_str()); } #else logger->log("resource(%s)", res->mIdPath.c_str()); @@ -631,6 +642,7 @@ void ResourceManager::deleteInstance() logger->log1("clean orphans end"); ResourceIterator iter = resourceManager->mResources.begin(); + bool status(false); while (iter != resourceManager->mResources.end()) { const Resource *const res = iter->second; @@ -641,10 +653,15 @@ void ResourceManager::deleteInstance() logger->log(std::string("ResourceLeak: ").append( res->getIdPath()).append(" (").append(toString( res->getRefCount())).append(")")); + status = true; } } ++iter; } +#ifdef UNITTESTS + if (status) + reportAlways("Found leaked resources."); +#endif } #endif delete2(resourceManager); -- cgit v1.2.3-70-g09d2