|
40 | 40 | #include "scene/main/node.h"
|
41 | 41 | #endif
|
42 | 42 |
|
| 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 | + |
43 | 51 | static ErrorHandlerList *error_handler_list = nullptr;
|
44 | 52 |
|
45 | 53 | 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
|
98 | 106 | }
|
99 | 107 |
|
100 | 108 | _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 | + |
101 | 128 | ErrorHandlerList *l = error_handler_list;
|
102 | 129 | while (l) {
|
103 | 130 | l->errfunc(l->userdata, p_function, p_file, p_line, p_error, p_message, p_editor_notify, p_type);
|
|
0 commit comments