Merge pull request #76586 from rcorre/register-language-race

Fix a race condition in ScriptServer
This commit is contained in:
Yuri Sizov 2023-06-22 12:44:25 +02:00 committed by GitHub
commit b0299c9ad1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -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();
}

View File

@ -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;