void Resource::set_path(const String &p_path, bool p_take_over) { if (path_cache == p_path) return; if (path_cache != "") { ResourceCache::resources.erase(path_cache); } path_cache = ""; if (ResourceCache::resources.has(p_path)) { if (p_take_over) { ResourceCache::resources.get(p_path)->set_name(""); } else { ERR_EXPLAIN("Another resource is loaded from path: " + p_path); ERR_FAIL_COND(ResourceCache::resources.has(p_path)); } } path_cache = p_path; if (path_cache != "") { ResourceCache::resources[path_cache] = this; } _change_notify("resource/path"); _resource_path_changed(); }
void Resource::set_path(const String &p_path, bool p_take_over) { if (path_cache == p_path) return; if (path_cache != "") { ResourceCache::lock->write_lock(); ResourceCache::resources.erase(path_cache); ResourceCache::lock->write_unlock(); } path_cache = ""; ResourceCache::lock->read_lock(); bool has_path = ResourceCache::resources.has(p_path); ResourceCache::lock->read_unlock(); if (has_path) { if (p_take_over) { ResourceCache::lock->write_lock(); ResourceCache::resources.get(p_path)->set_name(""); ResourceCache::lock->write_unlock(); } else { ERR_EXPLAIN("Another resource is loaded from path: " + p_path); ResourceCache::lock->read_lock(); bool exists = ResourceCache::resources.has(p_path); ResourceCache::lock->read_unlock(); ERR_FAIL_COND(exists); } } path_cache = p_path; if (path_cache != "") { ResourceCache::lock->write_lock(); ResourceCache::resources[path_cache] = this; ResourceCache::lock->write_unlock(); } _change_notify("resource_path"); _resource_path_changed(); }