From 718132b69404f1e55c97b7f0ad8c0055d032deaf Mon Sep 17 00:00:00 2001 From: lawnjelly Date: Sat, 5 Feb 2022 12:38:57 +0000 Subject: [PATCH] Add fflush to error macros CRASH_NOW and DEV_ASSERT macros would previously terminate before outputting any error messages. This PR ensures calling fflush for stdout before terminating. (cherry picked from commit ee979d321a4e067e5bb14944dfb33921622ebce6) --- core/error_macros.cpp | 4 ++++ core/error_macros.h | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/core/error_macros.cpp b/core/error_macros.cpp index 10c2bd847eb..448ef4e43dc 100644 --- a/core/error_macros.cpp +++ b/core/error_macros.cpp @@ -107,3 +107,7 @@ void _err_print_index_error(const char *p_function, const char *p_file, int p_li void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const String &p_message, bool fatal) { _err_print_index_error(p_function, p_file, p_line, p_index, p_size, p_index_str, p_size_str, p_message.utf8().get_data(), fatal); } + +void _err_flush_stdout() { + fflush(stdout); +} diff --git a/core/error_macros.h b/core/error_macros.h index 209dd9a4e12..cf540c3c332 100644 --- a/core/error_macros.h +++ b/core/error_macros.h @@ -84,6 +84,7 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, const String &p_message, ErrorHandlerType p_type = ERR_HANDLER_ERROR); void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const char *p_message = "", bool fatal = false); void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const String &p_message, bool fatal = false); +void _err_flush_stdout(); #ifndef _STR #define _STR(m_x) #m_x @@ -426,6 +427,7 @@ void _err_print_index_error(const char *p_function, const char *p_file, int p_li #define CRASH_NOW() \ if (true) { \ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Method failed."); \ + void _err_flush_stdout(); \ GENERATE_TRAP \ } else \ ((void)0) @@ -437,6 +439,7 @@ void _err_print_index_error(const char *p_function, const char *p_file, int p_li #define CRASH_NOW_MSG(m_msg) \ if (true) { \ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Method failed.", m_msg); \ + void _err_flush_stdout(); \ GENERATE_TRAP \ } else \ ((void)0) @@ -520,6 +523,7 @@ void _err_print_index_error(const char *p_function, const char *p_file, int p_li #define DEV_ASSERT(m_cond) \ if (unlikely(!(m_cond))) { \ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: DEV_ASSERT failed \"" _STR(m_cond) "\" is false."); \ + void _err_flush_stdout(); \ GENERATE_TRAP \ } else \ ((void)0)