Add an identity check to resource unregistration from cache

This is needed because resources loaded with CACHE_MODE_IGNORE still have path_cache set.
This commit is contained in:
Pedro J. Estébanez 2024-05-13 11:51:36 +02:00
parent bdc0316217
commit b70afac286
1 changed files with 11 additions and 4 deletions

View File

@ -570,11 +570,18 @@ Resource::Resource() :
remapped_list(this) {} remapped_list(this) {}
Resource::~Resource() { Resource::~Resource() {
if (!path_cache.is_empty()) { if (unlikely(path_cache.is_empty())) {
ResourceCache::lock.lock(); return;
ResourceCache::resources.erase(path_cache);
ResourceCache::lock.unlock();
} }
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; HashMap<String, Resource *> ResourceCache::resources;