You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-23 15:16:17 +00:00
Merge pull request #107058 from mihe/script-backtrace-deadlock
Fix various race conditions with capturing of script backtraces
This commit is contained in:
@@ -92,15 +92,7 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co
|
|||||||
// Main error printing function.
|
// Main error printing function.
|
||||||
void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, const char *p_message, bool p_editor_notify, ErrorHandlerType p_type) {
|
void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, const char *p_message, bool p_editor_notify, ErrorHandlerType p_type) {
|
||||||
if (OS::get_singleton()) {
|
if (OS::get_singleton()) {
|
||||||
Vector<Ref<ScriptBacktrace>> script_backtraces;
|
OS::get_singleton()->print_error(p_function, p_file, p_line, p_error, p_message, p_editor_notify, (Logger::ErrorType)p_type, ScriptServer::capture_script_backtraces(false));
|
||||||
|
|
||||||
// If script languages aren't initialized, we could be in the process of shutting down, in which case we don't want to allocate any objects, as we could be
|
|
||||||
// logging ObjectDB leaks, where ObjectDB would be locked, thus causing a deadlock.
|
|
||||||
if (ScriptServer::are_languages_initialized()) {
|
|
||||||
script_backtraces = ScriptServer::capture_script_backtraces(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
OS::get_singleton()->print_error(p_function, p_file, p_line, p_error, p_message, p_editor_notify, (Logger::ErrorType)p_type, script_backtraces);
|
|
||||||
} else {
|
} else {
|
||||||
// Fallback if errors happen before OS init or after it's destroyed.
|
// Fallback if errors happen before OS init or after it's destroyed.
|
||||||
const char *err_details = (p_message && *p_message) ? p_message : p_error;
|
const char *err_details = (p_message && *p_message) ? p_message : p_error;
|
||||||
|
|||||||
@@ -45,6 +45,15 @@ bool ScriptServer::scripting_enabled = true;
|
|||||||
bool ScriptServer::reload_scripts_on_save = false;
|
bool ScriptServer::reload_scripts_on_save = false;
|
||||||
ScriptEditRequestFunction ScriptServer::edit_request_func = nullptr;
|
ScriptEditRequestFunction ScriptServer::edit_request_func = nullptr;
|
||||||
|
|
||||||
|
// These need to be the last static variables in this file, since we're exploiting the reverse-order destruction of static variables.
|
||||||
|
static bool is_program_exiting = false;
|
||||||
|
struct ProgramExitGuard {
|
||||||
|
~ProgramExitGuard() {
|
||||||
|
is_program_exiting = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
static ProgramExitGuard program_exit_guard;
|
||||||
|
|
||||||
void Script::_notification(int p_what) {
|
void Script::_notification(int p_what) {
|
||||||
switch (p_what) {
|
switch (p_what) {
|
||||||
case NOTIFICATION_POSTINITIALIZE: {
|
case NOTIFICATION_POSTINITIALIZE: {
|
||||||
@@ -536,13 +545,21 @@ void ScriptServer::save_global_classes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Vector<Ref<ScriptBacktrace>> ScriptServer::capture_script_backtraces(bool p_include_variables) {
|
Vector<Ref<ScriptBacktrace>> ScriptServer::capture_script_backtraces(bool p_include_variables) {
|
||||||
int language_count = ScriptServer::get_language_count();
|
if (is_program_exiting) {
|
||||||
Vector<Ref<ScriptBacktrace>> result;
|
return Vector<Ref<ScriptBacktrace>>();
|
||||||
result.resize(language_count);
|
|
||||||
for (int i = 0; i < language_count; i++) {
|
|
||||||
ScriptLanguage *language = ScriptServer::get_language(i);
|
|
||||||
result.write[i].instantiate(language, p_include_variables);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MutexLock lock(languages_mutex);
|
||||||
|
if (!languages_ready) {
|
||||||
|
return Vector<Ref<ScriptBacktrace>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<Ref<ScriptBacktrace>> result;
|
||||||
|
result.resize(_language_count);
|
||||||
|
for (int i = 0; i < _language_count; i++) {
|
||||||
|
result.write[i].instantiate(_languages[i], p_include_variables);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -146,14 +146,11 @@ static void handle_crash(int sig) {
|
|||||||
print_error("-- END OF C++ BACKTRACE --");
|
print_error("-- END OF C++ BACKTRACE --");
|
||||||
print_error("================================================================");
|
print_error("================================================================");
|
||||||
|
|
||||||
if (ScriptServer::are_languages_initialized()) {
|
for (const Ref<ScriptBacktrace> &backtrace : ScriptServer::capture_script_backtraces(false)) {
|
||||||
Vector<Ref<ScriptBacktrace>> script_backtraces = ScriptServer::capture_script_backtraces(false);
|
if (!backtrace->is_empty()) {
|
||||||
for (const Ref<ScriptBacktrace> &backtrace : script_backtraces) {
|
print_error(backtrace->format());
|
||||||
if (!backtrace->is_empty()) {
|
print_error(vformat("-- END OF %s BACKTRACE --", backtrace->get_language_name().to_upper()));
|
||||||
print_error(backtrace->format());
|
print_error("================================================================");
|
||||||
print_error(vformat("-- END OF %s BACKTRACE --", backtrace->get_language_name().to_upper()));
|
|
||||||
print_error("================================================================");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -176,14 +176,11 @@ static void handle_crash(int sig) {
|
|||||||
print_error("-- END OF C++ BACKTRACE --");
|
print_error("-- END OF C++ BACKTRACE --");
|
||||||
print_error("================================================================");
|
print_error("================================================================");
|
||||||
|
|
||||||
if (ScriptServer::are_languages_initialized()) {
|
for (const Ref<ScriptBacktrace> &backtrace : ScriptServer::capture_script_backtraces(false)) {
|
||||||
Vector<Ref<ScriptBacktrace>> script_backtraces = ScriptServer::capture_script_backtraces(false);
|
if (!backtrace->is_empty()) {
|
||||||
for (const Ref<ScriptBacktrace> &backtrace : script_backtraces) {
|
print_error(backtrace->format());
|
||||||
if (!backtrace->is_empty()) {
|
print_error(vformat("-- END OF %s BACKTRACE --", backtrace->get_language_name().to_upper()));
|
||||||
print_error(backtrace->format());
|
print_error("================================================================");
|
||||||
print_error(vformat("-- END OF %s BACKTRACE --", backtrace->get_language_name().to_upper()));
|
|
||||||
print_error("================================================================");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -230,14 +230,11 @@ DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) {
|
|||||||
|
|
||||||
SymCleanup(process);
|
SymCleanup(process);
|
||||||
|
|
||||||
if (ScriptServer::are_languages_initialized()) {
|
for (const Ref<ScriptBacktrace> &backtrace : ScriptServer::capture_script_backtraces(false)) {
|
||||||
Vector<Ref<ScriptBacktrace>> script_backtraces = ScriptServer::capture_script_backtraces(false);
|
if (!backtrace->is_empty()) {
|
||||||
for (const Ref<ScriptBacktrace> &backtrace : script_backtraces) {
|
print_error(backtrace->format());
|
||||||
if (!backtrace->is_empty()) {
|
print_error(vformat("-- END OF %s BACKTRACE --", backtrace->get_language_name().to_upper()));
|
||||||
print_error(backtrace->format());
|
print_error("================================================================");
|
||||||
print_error(vformat("-- END OF %s BACKTRACE --", backtrace->get_language_name().to_upper()));
|
|
||||||
print_error("================================================================");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -184,14 +184,11 @@ extern void CrashHandlerException(int signal) {
|
|||||||
print_error("-- END OF C++ BACKTRACE --");
|
print_error("-- END OF C++ BACKTRACE --");
|
||||||
print_error("================================================================");
|
print_error("================================================================");
|
||||||
|
|
||||||
if (ScriptServer::are_languages_initialized()) {
|
for (const Ref<ScriptBacktrace> &backtrace : ScriptServer::capture_script_backtraces(false)) {
|
||||||
Vector<Ref<ScriptBacktrace>> script_backtraces = ScriptServer::capture_script_backtraces(false);
|
if (!backtrace->is_empty()) {
|
||||||
for (const Ref<ScriptBacktrace> &backtrace : script_backtraces) {
|
print_error(backtrace->format());
|
||||||
if (!backtrace->is_empty()) {
|
print_error(vformat("-- END OF %s BACKTRACE --", backtrace->get_language_name().to_upper()));
|
||||||
print_error(backtrace->format());
|
print_error("================================================================");
|
||||||
print_error(vformat("-- END OF %s BACKTRACE --", backtrace->get_language_name().to_upper()));
|
|
||||||
print_error("================================================================");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user