Skip to content

Commit

Permalink
Fix editor log flicker.
Browse files Browse the repository at this point in the history
  • Loading branch information
bruvzg committed Jun 12, 2023
1 parent 593d5ca commit 4886267
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
9 changes: 9 additions & 0 deletions editor/editor_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,15 @@ void EditorLog::_add_log_line(LogMessage &p_message, bool p_replace_previous) {
}

log->add_newline();

if (p_replace_previous) {
// Force sync last line update (skip if number of unprocessed log messages is too large to avoid editor lag).
if (log->get_pending_paragraphs() < 100) {
while (!log->is_ready()) {
::OS::get_singleton()->delay_usec(1);
}
}
}
}

void EditorLog::_set_filter_active(bool p_active, MessageType p_message_type) {
Expand Down
12 changes: 11 additions & 1 deletion scene/gui/rich_text_label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2741,7 +2741,16 @@ void RichTextLabel::_stop_thread() {
}
}

int RichTextLabel::get_pending_paragraphs() const {
int to_line = main->first_invalid_line.load();
int lines = main->lines.size();

return lines - to_line;
}

bool RichTextLabel::is_ready() const {
const_cast<RichTextLabel *>(this)->_validate_line_caches();

if (updating.load()) {
return false;
}
Expand Down Expand Up @@ -3177,7 +3186,8 @@ bool RichTextLabel::remove_paragraph(const int p_paragraph) {
main->lines[0].from = main;
}

main->first_invalid_line.store(0);
int to_line = main->first_invalid_line.load();
main->first_invalid_line.store(MIN(to_line, p_paragraph));
queue_redraw();

return true;
Expand Down
1 change: 1 addition & 0 deletions scene/gui/rich_text_label.h
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ class RichTextLabel : public Control {
bool is_deselect_on_focus_loss_enabled() const;
void deselect();

int get_pending_paragraphs() const;
bool is_ready() const;
bool is_updating() const;

Expand Down

0 comments on commit 4886267

Please sign in to comment.