Merge pull request #96499 from beev1s/shallow-script-cache-error

Fix resource loader not resolving shallow loaded scripts through dependencies
This commit is contained in:
Thaddeus Crews 2024-10-25 13:04:09 -05:00
commit 2584f75537
No known key found for this signature in database
GPG Key ID: 62181B86FE9E5D84
3 changed files with 23 additions and 1 deletions

View File

@ -1075,6 +1075,26 @@ void GDScript::_bind_methods() {
ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "new", &GDScript::_new, MethodInfo("new")); ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "new", &GDScript::_new, MethodInfo("new"));
} }
void GDScript::set_path_cache(const String &p_path) {
if (ResourceCache::has(p_path)) {
set_path(p_path, true);
return;
}
if (is_root_script()) {
Script::set_path_cache(p_path);
}
String old_path = path;
path = p_path;
path_valid = true;
GDScriptCache::move_script(old_path, p_path);
for (KeyValue<StringName, Ref<GDScript>> &kv : subclasses) {
kv.value->set_path_cache(p_path);
}
}
void GDScript::set_path(const String &p_path, bool p_take_over) { void GDScript::set_path(const String &p_path, bool p_take_over) {
if (is_root_script()) { if (is_root_script()) {
Script::set_path(p_path, p_take_over); Script::set_path(p_path, p_take_over);

View File

@ -300,6 +300,7 @@ public:
virtual Error reload(bool p_keep_state = false) override; virtual Error reload(bool p_keep_state = false) override;
virtual void set_path_cache(const String &p_path) override;
virtual void set_path(const String &p_path, bool p_take_over = false) override; virtual void set_path(const String &p_path, bool p_take_over = false) override;
String get_script_path() const; String get_script_path() const;
Error load_source_code(const String &p_path); Error load_source_code(const String &p_path);

View File

@ -312,7 +312,7 @@ Ref<GDScript> GDScriptCache::get_shallow_script(const String &p_path, Error &r_e
Ref<GDScript> script; Ref<GDScript> script;
script.instantiate(); script.instantiate();
script->set_path(p_path, true); script->set_path_cache(p_path);
if (remapped_path.get_extension().to_lower() == "gdc") { if (remapped_path.get_extension().to_lower() == "gdc") {
Vector<uint8_t> buffer = get_binary_tokens(remapped_path); Vector<uint8_t> buffer = get_binary_tokens(remapped_path);
if (buffer.is_empty()) { if (buffer.is_empty()) {
@ -360,6 +360,7 @@ Ref<GDScript> GDScriptCache::get_full_script(const String &p_path, Error &r_erro
return script; return script;
} }
} }
script->set_path(p_path, true);
const String remapped_path = ResourceLoader::path_remap(p_path); const String remapped_path = ResourceLoader::path_remap(p_path);