Skip to content

Commit a5ece5f

Browse files
Automatic collapse when too many messages are printed
1 parent aa25978 commit a5ece5f

File tree

2 files changed

+10
-27
lines changed

2 files changed

+10
-27
lines changed

core/error/error_macros.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@
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-
5143
static ErrorHandlerList *error_handler_list = nullptr;
5244

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

108100
_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-
128101
ErrorHandlerList *l = error_handler_list;
129102
while (l) {
130103
l->errfunc(l->userdata, p_function, p_file, p_line, p_error, p_message, p_editor_notify, p_type);

editor/editor_log.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#include "scene/gui/separator.h"
4343
#include "scene/resources/font.h"
4444

45+
#define MAX_MESSAGES_BEFORE_COLLAPSE 10
46+
4547
void EditorLog::_error_handler(void *p_self, const char *p_func, const char *p_file, int p_line, const char *p_error, const char *p_errorexp, bool p_editor_notify, ErrorHandlerType p_type) {
4648
EditorLog *self = static_cast<EditorLog *>(p_self);
4749

@@ -230,6 +232,14 @@ void EditorLog::_process_message(const String &p_msg, MessageType p_type, bool p
230232
LogMessage &previous = messages.write[messages.size() - 1];
231233
previous.count++;
232234

235+
if (!collapse && previous.count == MAX_MESSAGES_BEFORE_COLLAPSE) {
236+
if (!Thread::is_main_thread()) {
237+
MessageQueue::get_main_singleton()->push_callable(callable_mp(this, &EditorLog::_set_collapse), true);
238+
} else {
239+
_set_collapse(true);
240+
}
241+
}
242+
233243
_add_log_line(previous, collapse);
234244
} else {
235245
// Different message to the previous one received.

0 commit comments

Comments
 (0)