summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/widgets/desktop.cpp4
-rw-r--r--src/resources/resourcemanager.cpp31
-rw-r--r--src/resources/resourcemanager.h2
3 files changed, 35 insertions, 2 deletions
diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp
index 2be86f615..32c8a4988 100644
--- a/src/gui/widgets/desktop.cpp
+++ b/src/gui/widgets/desktop.cpp
@@ -162,7 +162,7 @@ void Desktop::setBestFittingWallpaper()
ResourceManager *const resman = ResourceManager::getInstance();
if (mWallpaper)
{
- resman->moveToDeleted(mWallpaper);
+ resman->decRefDelete(mWallpaper);
mWallpaper = nullptr;
}
@@ -180,7 +180,7 @@ void Desktop::setBestFittingWallpaper()
if (newRsclWlPpr)
{
- resman->moveToDeleted(nWallPaper);
+ resman->decRefDelete(nWallPaper);
// We replace the resource in the resource manager
mWallpaper = newRsclWlPpr;
}
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 00fe37c75..fa0717622 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -887,6 +887,37 @@ void ResourceManager::moveToDeleted(Resource *const res)
}
}
+void ResourceManager::decRefDelete(Resource *const res)
+{
+ if (!res)
+ return;
+
+ bool found(false);
+ const int count = res->getRefCount();
+ if (count == 1)
+ {
+ logResource(res);
+
+ ResourceIterator resIter = mResources.find(res->mIdPath);
+ if (resIter != mResources.end() && resIter->second == res)
+ {
+ mResources.erase(resIter);
+ }
+ else
+ {
+ resIter = mOrphanedResources.find(res->mIdPath);
+ if (resIter != mOrphanedResources.end() && resIter->second == res)
+ mOrphanedResources.erase(resIter);
+ }
+
+ delete res;
+ }
+ else
+ {
+ res->decRef();
+ }
+}
+
ResourceManager *ResourceManager::getInstance()
{
// Create a new instance if necessary.
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index 83c0036f2..72cad5988 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -240,6 +240,8 @@ class ResourceManager final
void clearDeleted(const bool full = true);
+ void decRefDelete(Resource *const res);
+
static void logResource(const Resource *const res);
/**