Skip to content

Commit

Permalink
Make EditorToaster's handler thread-safe
Browse files Browse the repository at this point in the history
(cherry picked from commit 84183f8)
  • Loading branch information
RandomShaper authored and YuriSizov committed Apr 24, 2023
1 parent 3fcaffc commit 3a5bc74
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
17 changes: 9 additions & 8 deletions editor/editor_toaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ void EditorToaster::_notification(int p_what) {
}

void EditorToaster::_error_handler(void *p_self, const char *p_func, const char *p_file, int p_line, const char *p_error, const char *p_errorexp, bool p_editor_notify, ErrorHandlerType p_type) {
// This may be called from a thread. Since we will deal with non-thread-safe elements,
// we have to put it in the queue for safety.
callable_mp_static(&EditorToaster::_error_handler_impl).bind(p_file, p_line, p_error, p_errorexp, p_editor_notify, p_type).call_deferred();
}

void EditorToaster::_error_handler_impl(const String &p_file, int p_line, const String &p_error, const String &p_errorexp, bool p_editor_notify, int p_type) {
if (!EditorToaster::get_singleton() || !EditorToaster::get_singleton()->is_inside_tree()) {
return;
}
Expand All @@ -158,13 +164,8 @@ void EditorToaster::_error_handler(void *p_self, const char *p_func, const char
int show_all_setting = EDITOR_GET("interface/editor/show_internal_errors_in_toast_notifications");

if (p_editor_notify || (show_all_setting == 0 && in_dev) || show_all_setting == 1) {
String err_str;
if (p_errorexp && p_errorexp[0]) {
err_str = String::utf8(p_errorexp);
} else {
err_str = String::utf8(p_error);
}
String tooltip_str = String::utf8(p_file) + ":" + itos(p_line);
String err_str = !p_errorexp.is_empty() ? p_errorexp : p_error;
String tooltip_str = p_file + ":" + itos(p_line);

if (!p_editor_notify) {
if (p_type == ERR_HANDLER_WARNING) {
Expand All @@ -174,7 +175,7 @@ void EditorToaster::_error_handler(void *p_self, const char *p_func, const char
}
}

Severity severity = (p_type == ERR_HANDLER_WARNING) ? SEVERITY_WARNING : SEVERITY_ERROR;
Severity severity = ((ErrorHandlerType)p_type == ERR_HANDLER_WARNING) ? SEVERITY_WARNING : SEVERITY_ERROR;
EditorToaster::get_singleton()->popup_str(err_str, severity, tooltip_str);
}
}
Expand Down
1 change: 1 addition & 0 deletions editor/editor_toaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class EditorToaster : public HBoxContainer {
const double default_message_duration = 5.0;

static void _error_handler(void *p_self, const char *p_func, const char *p_file, int p_line, const char *p_error, const char *p_errorexp, bool p_editor_notify, ErrorHandlerType p_type);
static void _error_handler_impl(const String &p_file, int p_line, const String &p_error, const String &p_errorexp, bool p_editor_notify, int p_type);
void _update_vbox_position();
void _update_disable_notifications_button();
void _auto_hide_or_free_toasts();
Expand Down

0 comments on commit 3a5bc74

Please sign in to comment.