summaryrefslogtreecommitdiffstats
path: root/core/io/resource.cpp
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2024-05-13 11:51:36 +0200
committerPedro J. Estébanez <pedrojrulez@gmail.com>2024-05-13 11:55:50 +0200
commitb70afac286ce723b2b0d71b81e0a5dcf0e0034d2 (patch)
treeedb73e5cd2e51abf85bffe0e817702be1df6d9b4 /core/io/resource.cpp
parentbdc0316217940a8ccc80ce536547d42e6477adf4 (diff)
downloadredot-engine-b70afac286ce723b2b0d71b81e0a5dcf0e0034d2.tar.gz
Add an identity check to resource unregistration from cache
This is needed because resources loaded with CACHE_MODE_IGNORE still have path_cache set.
Diffstat (limited to 'core/io/resource.cpp')
-rw-r--r--core/io/resource.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/core/io/resource.cpp b/core/io/resource.cpp
index 4c3cfeaa58..00b669aa1c 100644
--- a/core/io/resource.cpp
+++ b/core/io/resource.cpp
@@ -570,11 +570,18 @@ Resource::Resource() :
remapped_list(this) {}
Resource::~Resource() {
- if (!path_cache.is_empty()) {
- ResourceCache::lock.lock();
- ResourceCache::resources.erase(path_cache);
- ResourceCache::lock.unlock();
+ if (unlikely(path_cache.is_empty())) {
+ return;
}
+
+ ResourceCache::lock.lock();
+ // Only unregister from the cache if this is the actual resource listed there.
+ // (Other resources can have the same value in `path_cache` if loaded with `CACHE_IGNORE`.)
+ HashMap<String, Resource *>::Iterator E = ResourceCache::resources.find(path_cache);
+ if (likely(E && E->value == this)) {
+ ResourceCache::resources.remove(E);
+ }
+ ResourceCache::lock.unlock();
}
HashMap<String, Resource *> ResourceCache::resources;