summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-05-16 09:32:03 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-05-16 09:32:03 +0200
commit944b95e1a5a9c01314224c9ec34ace3fb80dc336 (patch)
treed64bd8a44135a3671d8906c6492a19592c09abb7 /core
parentc27f24da81a6b5a3282a16a10a8e3749cde4ef7c (diff)
parentb70afac286ce723b2b0d71b81e0a5dcf0e0034d2 (diff)
downloadredot-engine-944b95e1a5a9c01314224c9ec34ace3fb80dc336.tar.gz
Merge pull request #91897 from RandomShaper/res_unreg_if_true
Add an identity check to resource unregistration from cache
Diffstat (limited to 'core')
-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 573692f41e..1ecfd8366d 100644
--- a/core/io/resource.cpp
+++ b/core/io/resource.cpp
@@ -569,11 +569,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;