Skip to content

Commit

Permalink
Fix a bug in the logger.
Browse files Browse the repository at this point in the history
  • Loading branch information
anirul committed Feb 20, 2024
1 parent 7355ff6 commit ee3d751
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/frame/gui/window_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ void WindowLogger::LogWithColor(const LogMessage& log_message) const
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
break;
default:
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
break;
throw std::runtime_error("Unknown log level!");
}
ImGui::TextUnformatted(log_message.message.c_str());
ImGui::PopStyleColor();
Expand Down
9 changes: 3 additions & 6 deletions src/frame/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,16 @@ const std::vector<LogMessage>& Logger::GetLastLogs(std::uint32_t max_log) const
std::dynamic_pointer_cast<frame::gui::GuiLoggerSink>(gui_logger_sink_);
if (gui_logger_sink)
{
if (display_logs_.capacity() != max_log)
{
display_logs_.reserve(max_log);
}
const auto& logs = gui_logger_sink->GetLogs();
if (logs.size() <= max_log)
{
return logs;
}
display_logs_.clear();
for (std::size_t i = logs.size() - max_log; i < logs.size(); ++i)
std::size_t start = logs.size() - max_log;
for (std::size_t i = 0; i < max_log; ++i)
{
display_logs_.push_back(logs[i]);
display_logs_.push_back(logs[start + i]);
}
return display_logs_;
}
Expand Down

0 comments on commit ee3d751

Please sign in to comment.