diff options
| author | Rindbee <idleman@yeah.net> | 2023-05-11 22:32:16 +0800 |
|---|---|---|
| committer | Rindbee <idleman@yeah.net> | 2023-06-15 21:06:10 +0800 |
| commit | cbce374f68b1148020786dec24127ccd89209afa (patch) | |
| tree | 320d9eacc654a180581d57dd30f62667a344a5a3 | |
| parent | 773414606079fa745d1c37fce49324ab6a09e972 (diff) | |
| download | redot-engine-cbce374f68b1148020786dec24127ccd89209afa.tar.gz | |
Returns null and does not cache when the source code of the script fails to load
This usually means that an `ERR_FILE*` error occurred.
Previously, using `GDScriptCache::get_full_script()` would ignore errors during loading.
Now, all errors are not ignored.
Judging in which period the error occurred, it can be judged based on the return value:
1. null + err : Error during script loading (load_source_code()).
2. script + err: Error during script parsing.
| -rw-r--r-- | modules/gdscript/gdscript.cpp | 12 | ||||
| -rw-r--r-- | modules/gdscript/gdscript_cache.cpp | 6 |
2 files changed, 7 insertions, 11 deletions
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 945dfc9862..699d95e538 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -2592,20 +2592,12 @@ Ref<GDScript> GDScriptLanguage::get_script_by_fully_qualified_name(const String /*************** RESOURCE ***************/ Ref<Resource> ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { - if (r_error) { - *r_error = ERR_FILE_CANT_OPEN; - } - Error err; Ref<GDScript> scr = GDScriptCache::get_full_script(p_path, err, "", p_cache_mode == CACHE_MODE_IGNORE); - if (scr.is_null()) { - // Don't fail loading because of parsing error. - scr.instantiate(); - } - if (r_error) { - *r_error = OK; + // Don't fail loading because of parsing error. + *r_error = scr.is_valid() ? OK : err; } return scr; diff --git a/modules/gdscript/gdscript_cache.cpp b/modules/gdscript/gdscript_cache.cpp index 126fccbbf0..f06ce9ea7b 100644 --- a/modules/gdscript/gdscript_cache.cpp +++ b/modules/gdscript/gdscript_cache.cpp @@ -253,7 +253,11 @@ Ref<GDScript> GDScriptCache::get_shallow_script(const String &p_path, Error &r_e Ref<GDScript> script; script.instantiate(); script->set_path(p_path, true); - script->load_source_code(p_path); + r_error = script->load_source_code(p_path); + + if (r_error) { + return Ref<GDScript>(); // Returns null and does not cache when the script fails to load. + } Ref<GDScriptParserRef> parser_ref = get_parser(p_path, GDScriptParserRef::PARSED, r_error); if (r_error == OK) { |
