Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a race condition in ScriptServer #76586

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions core/object/script_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}
Expand Down
5 changes: 3 additions & 2 deletions core/object/script_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -97,7 +98,7 @@ class ScriptServer {
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;
Expand Down