Sfoglia il codice sorgente

Merge pull request #76954 from Rindbee/return-null-on-fail-load-script

Returns null and does not cache when the source code of the script fails to load
Rémi Verschelde 2 anni fa
parent
commit
5f9175f969
2 ha cambiato i file con 7 aggiunte e 11 eliminazioni
  1. 2 10
      modules/gdscript/gdscript.cpp
  2. 5 1
      modules/gdscript/gdscript_cache.cpp

+ 2 - 10
modules/gdscript/gdscript.cpp

@@ -2596,20 +2596,12 @@ Ref<GDScript> GDScriptLanguage::get_script_by_fully_qualified_name(const String
 /*************** RESOURCE ***************/
 /*************** 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) {
 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;
 	Error err;
 	Ref<GDScript> scr = GDScriptCache::get_full_script(p_path, err, "", p_cache_mode == CACHE_MODE_IGNORE);
 	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) {
 	if (r_error) {
-		*r_error = OK;
+		// Don't fail loading because of parsing error.
+		*r_error = scr.is_valid() ? OK : err;
 	}
 	}
 
 
 	return scr;
 	return scr;

+ 5 - 1
modules/gdscript/gdscript_cache.cpp

@@ -254,7 +254,11 @@ 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(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);
 	Ref<GDScriptParserRef> parser_ref = get_parser(p_path, GDScriptParserRef::PARSED, r_error);
 	if (r_error == OK) {
 	if (r_error == OK) {