Skip to content

Commit

Permalink
Merge pull request godotengine#91897 from RandomShaper/res_unreg_if_true
Browse files Browse the repository at this point in the history
Add an identity check to resource unregistration from cache
  • Loading branch information
akien-mga committed May 16, 2024
2 parents c27f24d + b70afac commit 944b95e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions core/io/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 944b95e

Please sign in to comment.