Browse Source

Merge pull request #102933 from KoBeWi/antivirus

Don't synchronize scripts with errors
Thaddeus Crews 3 months ago
parent
commit
f0edac3d36
2 changed files with 12 additions and 1 deletions
  1. 11 0
      editor/plugins/script_editor_plugin.cpp
  2. 1 1
      modules/gdscript/gdscript_editor.cpp

+ 11 - 0
editor/plugins/script_editor_plugin.cpp

@@ -1099,6 +1099,17 @@ void ScriptEditor::_mark_built_in_scripts_as_saved(const String &p_parent_path)
 
 void ScriptEditor::trigger_live_script_reload(const String &p_script_path) {
 	if (!script_paths_to_reload.has(p_script_path)) {
+		Ref<Script> reloaded_script = ResourceCache::get_ref(p_script_path);
+		if (reloaded_script.is_null()) {
+			reloaded_script = ResourceLoader::load(p_script_path);
+		}
+		if (reloaded_script.is_valid()) {
+			if (!reloaded_script->get_language()->validate(reloaded_script->get_source_code(), p_script_path)) {
+				// Script has errors, don't live reload.
+				return;
+			}
+		}
+
 		script_paths_to_reload.append(p_script_path);
 	}
 	if (!pending_auto_reload && auto_reload_running_scripts) {

+ 1 - 1
modules/gdscript/gdscript_editor.cpp

@@ -177,7 +177,7 @@ bool GDScriptLanguage::validate(const String &p_script, const String &p_path, Li
 			}
 		}
 		return false;
-	} else {
+	} else if (r_functions) {
 		const GDScriptParser::ClassNode *cl = parser.get_tree();
 		HashMap<int, String> funcs;