Skip to content

Commit aa25978

Browse files
Limit propagation of error to handlers to 6 consecutive errors
1 parent d7acc23 commit aa25978

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

core/error/error_macros.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
#include "scene/main/node.h"
4141
#endif
4242

43+
int repetitions_last_line = -1;
44+
const char *repetitions_last_function = NULL;
45+
// No need to initialize: by constructon, can never be checked if line/function don't match.
46+
char repetitions_last_message[256];
47+
int repetitions_last_message_count = 0;
48+
const int MAX_LOG_MESSAGE_REPETITIONS = 6;
49+
const char *REPETITIONS_WARNING_MESSAGE = "Last message repeated 6 times...";
50+
4351
static ErrorHandlerList *error_handler_list = nullptr;
4452

4553
void add_error_handler(ErrorHandlerList *p_handler) {
@@ -98,6 +106,25 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co
98106
}
99107

100108
_global_lock();
109+
110+
if (repetitions_last_line == p_line && repetitions_last_function == p_function && ::strcmp(p_message, repetitions_last_message) == 0) {
111+
if (repetitions_last_message_count == MAX_LOG_MESSAGE_REPETITIONS) {
112+
p_message = REPETITIONS_WARNING_MESSAGE;
113+
repetitions_last_message_count += 1; // avoid rollover errors
114+
} else if (repetitions_last_message_count < MAX_LOG_MESSAGE_REPETITIONS) {
115+
repetitions_last_message_count += 1;
116+
} else {
117+
_global_unlock();
118+
return;
119+
}
120+
} else {
121+
repetitions_last_message_count = 0;
122+
repetitions_last_line = p_line;
123+
repetitions_last_function = p_function;
124+
// The message memory lifetime may end after this call.
125+
::strncpy(repetitions_last_message, p_message, sizeof(repetitions_last_message));
126+
}
127+
101128
ErrorHandlerList *l = error_handler_list;
102129
while (l) {
103130
l->errfunc(l->userdata, p_function, p_file, p_line, p_error, p_message, p_editor_notify, p_type);

0 commit comments

Comments
 (0)