Skip to content

Commit

Permalink
🐛 [MessageConsole] Do the limiting of the size during imgui_window() …
Browse files Browse the repository at this point in the history
…to avoid deadlocks
  • Loading branch information
JulesFouchy committed Aug 4, 2023
1 parent ed6e652 commit 62f4f78
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
24 changes: 16 additions & 8 deletions src/Cool/Log/MessageConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,6 @@ void MessageConsole::on_message_sent(const internal::RawMessageId& id)
{
_is_open = true;
_message_just_sent = id;
if (_messages.underlying_container().underlying_container().size() > 999) // If there are too many messages the console starts to cause lag.
{
auto const it = std::find_if(_messages.begin(), _messages.end(), [](auto const& pair) {
return is_clearable(pair.second);
});
if (it != _messages.end())
_messages.underlying_container().underlying_container().erase(it);
}
}

void MessageConsole::remove(const MessageId& id)
Expand Down Expand Up @@ -195,8 +187,24 @@ void MessageConsole::show_number_of_messages_of_given_severity(MessageSeverity s
}
}

void MessageConsole::remove_messages_to_keep_size_below(size_t max_number_of_messages)
{
while (_messages.underlying_container().underlying_container().size() > max_number_of_messages)
{
auto const it = std::find_if(_messages.begin(), _messages.end(), [](auto const& pair) {
return is_clearable(pair.second);
});
if (it != _messages.end())
_messages.underlying_container().underlying_container().erase(it);
else
break;
}
}

void MessageConsole::imgui_window()
{
remove_messages_to_keep_size_below(999); // If there are too many messages the console starts to cause lag.

if (_is_open)
{
refresh_counts_per_severity();
Expand Down
23 changes: 12 additions & 11 deletions src/Cool/Log/MessageConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,18 @@ class MessageConsole {
void imgui_window();

private:
void remove(const internal::RawMessageId&);
void close_window_if_empty();
void close_window();
void on_message_sent(const internal::RawMessageId&);
void show_number_of_messages_of_given_severity(MessageSeverity);
void refresh_counts_per_severity();
void imgui_menu_bar();
void imgui_show_all_messages();
auto there_are_clearable_messages() const -> bool;
auto there_are_clearable_messages(MessageSeverity) const -> bool;
auto should_show(const internal::MessageWithMetadata&) const -> bool;
void remove(const internal::RawMessageId&);
void close_window_if_empty();
void close_window();
void on_message_sent(const internal::RawMessageId&);
void show_number_of_messages_of_given_severity(MessageSeverity);
void refresh_counts_per_severity();
void imgui_menu_bar();
void imgui_show_all_messages();
[[nodiscard]] auto there_are_clearable_messages() const -> bool;
[[nodiscard]] auto there_are_clearable_messages(MessageSeverity) const -> bool;
[[nodiscard]] auto should_show(const internal::MessageWithMetadata&) const -> bool;
void remove_messages_to_keep_size_below(size_t max_number_of_messages);

class MessagesCountPerSeverity {
public:
Expand Down

0 comments on commit 62f4f78

Please sign in to comment.