1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Merge pull request #109122 from mihe/ext-resource-id-caching

Fix external resource IDs being lost for default properties
This commit is contained in:
Thaddeus Crews
2025-07-31 10:38:45 -05:00
3 changed files with 16 additions and 12 deletions

View File

@@ -672,25 +672,25 @@ void Resource::set_as_translation_remapped(bool p_remapped) {
}
// Helps keep IDs the same when loading/saving scenes. An empty ID clears the entry, and an empty ID is returned when not found.
void Resource::set_id_for_path(const String &p_path, const String &p_id) {
void Resource::set_resource_id_for_path(const String &p_referrer_path, const String &p_resource_path, const String &p_id) {
#ifdef TOOLS_ENABLED
if (p_id.is_empty()) {
ResourceCache::path_cache_lock.write_lock();
ResourceCache::resource_path_cache[p_path].erase(get_path());
ResourceCache::resource_path_cache[p_referrer_path].erase(p_resource_path);
ResourceCache::path_cache_lock.write_unlock();
} else {
ResourceCache::path_cache_lock.write_lock();
ResourceCache::resource_path_cache[p_path][get_path()] = p_id;
ResourceCache::resource_path_cache[p_referrer_path][p_resource_path] = p_id;
ResourceCache::path_cache_lock.write_unlock();
}
#endif
}
String Resource::get_id_for_path(const String &p_path) const {
String Resource::get_id_for_path(const String &p_referrer_path) const {
#ifdef TOOLS_ENABLED
ResourceCache::path_cache_lock.read_lock();
if (ResourceCache::resource_path_cache[p_path].has(get_path())) {
String result = ResourceCache::resource_path_cache[p_path][get_path()];
if (ResourceCache::resource_path_cache[p_referrer_path].has(get_path())) {
String result = ResourceCache::resource_path_cache[p_referrer_path][get_path()];
ResourceCache::path_cache_lock.read_unlock();
return result;
} else {

View File

@@ -181,8 +181,9 @@ public:
virtual RID get_rid() const; // Some resources may offer conversion to RID.
// Helps keep IDs the same when loading/saving scenes. An empty ID clears the entry, and an empty ID is returned when not found.
void set_id_for_path(const String &p_path, const String &p_id);
String get_id_for_path(const String &p_path) const;
static void set_resource_id_for_path(const String &p_referrer_path, const String &p_resource_path, const String &p_id);
void set_id_for_path(const String &p_referrer_path, const String &p_id) { set_resource_id_for_path(p_referrer_path, get_path(), p_id); }
String get_id_for_path(const String &p_referrer_path) const;
Resource();
~Resource();