diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp index 6f047d80aaa..a8b0e426aea 100644 --- a/core/object/script_language.cpp +++ b/core/object/script_language.cpp @@ -42,7 +42,7 @@ int ScriptServer::_language_count = 0; bool ScriptServer::scripting_enabled = true; bool ScriptServer::reload_scripts_on_save = false; -bool ScriptServer::languages_finished = false; +SafeFlag ScriptServer::languages_finished; // Used until GH-76581 is fixed properly. ScriptEditRequestFunction ScriptServer::edit_request_func = nullptr; void Script::_notification(int p_what) { @@ -228,7 +228,7 @@ void ScriptServer::finish_languages() { _languages[i]->finish(); } global_classes_clear(); - languages_finished = true; + languages_finished.set(); } void ScriptServer::set_reload_scripts_on_save(bool p_enable) { @@ -240,12 +240,18 @@ bool ScriptServer::is_reload_scripts_on_save_enabled() { } void ScriptServer::thread_enter() { + if (!languages_finished.is_set()) { + return; + } for (int i = 0; i < _language_count; i++) { _languages[i]->thread_enter(); } } void ScriptServer::thread_exit() { + if (!languages_finished.is_set()) { + return; + } for (int i = 0; i < _language_count; i++) { _languages[i]->thread_exit(); } diff --git a/core/object/script_language.h b/core/object/script_language.h index c22890e30a0..2b685c77a3e 100644 --- a/core/object/script_language.h +++ b/core/object/script_language.h @@ -35,6 +35,7 @@ #include "core/io/resource.h" #include "core/templates/pair.h" #include "core/templates/rb_map.h" +#include "core/templates/safe_refcount.h" #include "core/variant/typed_array.h" class ScriptLanguage; @@ -52,7 +53,7 @@ class ScriptServer { static int _language_count; static bool scripting_enabled; static bool reload_scripts_on_save; - static bool languages_finished; + static SafeFlag languages_finished; // Used until GH-76581 is fixed properly. struct GlobalScriptClass { StringName language; @@ -97,7 +98,7 @@ public: static void init_languages(); static void finish_languages(); - static bool are_languages_finished() { return languages_finished; } + static bool are_languages_finished() { return languages_finished.is_set(); } }; class ScriptInstance;