Defer the call to 'popup_str' to the next cycle to let Godot Engine's editor time to properly start
This commit is contained in:
parent
15aea89868
commit
ba0abd399f
@ -37,9 +37,16 @@
|
|||||||
static ErrorHandlerList *error_handler_list = nullptr;
|
static ErrorHandlerList *error_handler_list = nullptr;
|
||||||
|
|
||||||
void add_error_handler(ErrorHandlerList *p_handler) {
|
void add_error_handler(ErrorHandlerList *p_handler) {
|
||||||
|
// If p_handler is already in error_handler_list
|
||||||
|
// we'd better remove it first then we can add it.
|
||||||
|
// This prevent cyclic redundancy.
|
||||||
|
remove_error_handler(p_handler);
|
||||||
|
|
||||||
_global_lock();
|
_global_lock();
|
||||||
|
|
||||||
p_handler->next = error_handler_list;
|
p_handler->next = error_handler_list;
|
||||||
error_handler_list = p_handler;
|
error_handler_list = p_handler;
|
||||||
|
|
||||||
_global_unlock();
|
_global_unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,11 +173,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 = (p_type == ERR_HANDLER_WARNING) ? SEVERITY_WARNING : SEVERITY_ERROR;
|
||||||
if (Thread::get_caller_id() != Thread::get_main_id()) {
|
EditorToaster::get_singleton()->popup_str(err_str, severity, tooltip_str);
|
||||||
EditorToaster::get_singleton()->call_deferred(SNAME("popup_str"), err_str, severity, tooltip_str);
|
|
||||||
} else {
|
|
||||||
EditorToaster::get_singleton()->popup_str(err_str, severity, tooltip_str);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,6 +383,12 @@ Control *EditorToaster::popup(Control *p_control, Severity p_severity, double p_
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EditorToaster::popup_str(String p_message, Severity p_severity, String p_tooltip) {
|
void EditorToaster::popup_str(String p_message, Severity p_severity, String p_tooltip) {
|
||||||
|
// 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.
|
||||||
|
call_deferred(SNAME("_popup_str"), p_message, p_severity, p_tooltip);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorToaster::_popup_str(String p_message, Severity p_severity, String p_tooltip) {
|
||||||
// Check if we already have a popup with the given message.
|
// Check if we already have a popup with the given message.
|
||||||
Control *control = nullptr;
|
Control *control = nullptr;
|
||||||
for (KeyValue<Control *, Toast> element : toasts) {
|
for (KeyValue<Control *, Toast> element : toasts) {
|
||||||
@ -440,6 +442,11 @@ EditorToaster *EditorToaster::get_singleton() {
|
|||||||
return singleton;
|
return singleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditorToaster::_bind_methods() {
|
||||||
|
// Binding method to make it defer-able.
|
||||||
|
ClassDB::bind_method(D_METHOD("_popup_str", "message", "severity", "tooltip"), &EditorToaster::_popup_str);
|
||||||
|
}
|
||||||
|
|
||||||
EditorToaster::EditorToaster() {
|
EditorToaster::EditorToaster() {
|
||||||
set_notify_transform(true);
|
set_notify_transform(true);
|
||||||
set_process_internal(true);
|
set_process_internal(true);
|
||||||
|
@ -94,9 +94,11 @@ private:
|
|||||||
|
|
||||||
void _set_notifications_enabled(bool p_enabled);
|
void _set_notifications_enabled(bool p_enabled);
|
||||||
void _repop_old();
|
void _repop_old();
|
||||||
|
void _popup_str(String p_message, Severity p_severity, String p_tooltip);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static EditorToaster *singleton;
|
static EditorToaster *singleton;
|
||||||
|
static void _bind_methods();
|
||||||
|
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user