Prevent infinite recursion during printing
This commit is contained in:
parent
71a9948157
commit
836a1a0b02
4 changed files with 70 additions and 14 deletions
|
|
@ -34,6 +34,11 @@
|
|||
#include "core/os/os.h"
|
||||
|
||||
static PrintHandlerList *print_handler_list = nullptr;
|
||||
static thread_local bool is_printing = false;
|
||||
|
||||
static void __print_fallback(const String &p_string, bool p_err) {
|
||||
fprintf(p_err ? stderr : stdout, "While attempting to print a message, another message was printed:\n%s\n", p_string.utf8().get_data());
|
||||
}
|
||||
|
||||
void add_print_handler(PrintHandlerList *p_handler) {
|
||||
_global_lock();
|
||||
|
|
@ -71,6 +76,13 @@ void __print_line(const String &p_string) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (is_printing) {
|
||||
__print_fallback(p_string, false);
|
||||
return;
|
||||
}
|
||||
|
||||
is_printing = true;
|
||||
|
||||
OS::get_singleton()->print("%s\n", p_string.utf8().get_data());
|
||||
|
||||
_global_lock();
|
||||
|
|
@ -81,6 +93,8 @@ void __print_line(const String &p_string) {
|
|||
}
|
||||
|
||||
_global_unlock();
|
||||
|
||||
is_printing = false;
|
||||
}
|
||||
|
||||
void __print_line_rich(const String &p_string) {
|
||||
|
|
@ -263,6 +277,13 @@ void __print_line_rich(const String &p_string) {
|
|||
}
|
||||
output += "\u001b[0m"; // Reset.
|
||||
|
||||
if (is_printing) {
|
||||
__print_fallback(output, false);
|
||||
return;
|
||||
}
|
||||
|
||||
is_printing = true;
|
||||
|
||||
OS::get_singleton()->print_rich("%s\n", output.utf8().get_data());
|
||||
|
||||
_global_lock();
|
||||
|
|
@ -273,6 +294,8 @@ void __print_line_rich(const String &p_string) {
|
|||
}
|
||||
|
||||
_global_unlock();
|
||||
|
||||
is_printing = false;
|
||||
}
|
||||
|
||||
void print_error(const String &p_string) {
|
||||
|
|
@ -280,6 +303,13 @@ void print_error(const String &p_string) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (is_printing) {
|
||||
__print_fallback(p_string, true);
|
||||
return;
|
||||
}
|
||||
|
||||
is_printing = true;
|
||||
|
||||
OS::get_singleton()->printerr("%s\n", p_string.utf8().get_data());
|
||||
|
||||
_global_lock();
|
||||
|
|
@ -290,6 +320,8 @@ void print_error(const String &p_string) {
|
|||
}
|
||||
|
||||
_global_unlock();
|
||||
|
||||
is_printing = false;
|
||||
}
|
||||
|
||||
bool is_print_verbose_enabled() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue