From 0a15706aca58a7c566af373f37bb368570f24242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gilles=20Roudi=C3=A8re?= Date: Tue, 8 Mar 2022 11:12:25 +0100 Subject: [PATCH] Avoid recursive errors in EditorToaster --- editor/editor_toaster.cpp | 8 ++++++++ editor/editor_toaster.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/editor/editor_toaster.cpp b/editor/editor_toaster.cpp index 319b4709fef..7ca88bd2a28 100644 --- a/editor/editor_toaster.cpp +++ b/editor/editor_toaster.cpp @@ -385,12 +385,19 @@ Control *EditorToaster::popup(Control *p_control, Severity p_severity, double p_ } void EditorToaster::popup_str(String p_message, Severity p_severity, String p_tooltip) { + if (is_processing_error) { + return; + } + // Since "_popup_str" adds nodes to the tree, and since the "add_child" method is not // thread-safe, it's better to defer the call to the next cycle to be thread-safe. + is_processing_error = true; call_deferred(SNAME("_popup_str"), p_message, p_severity, p_tooltip); + is_processing_error = false; } void EditorToaster::_popup_str(String p_message, Severity p_severity, String p_tooltip) { + is_processing_error = true; // Check if we already have a popup with the given message. Control *control = nullptr; for (KeyValue element : toasts) { @@ -432,6 +439,7 @@ void EditorToaster::_popup_str(String p_message, Severity p_severity, String p_t } else { label->set_text(vformat("%s (%d)", p_message, toasts[control].count)); } + is_processing_error = false; } void EditorToaster::close(Control *p_control) { diff --git a/editor/editor_toaster.h b/editor/editor_toaster.h index 2ad8752bee6..059245ce662 100644 --- a/editor/editor_toaster.h +++ b/editor/editor_toaster.h @@ -82,6 +82,8 @@ private: }; Map toasts; + bool is_processing_error = false; // Makes sure that we don't handle errors that are triggered within the EditorToaster error processing. + 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);