Skip to content

Commit

Permalink
GUI/TTY: fix UI deadlock when TTY is being spammed
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 committed Oct 17, 2022
1 parent 87797e1 commit e7a9e9d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
44 changes: 29 additions & 15 deletions rpcs3/rpcs3qt/log_frame.cpp
Expand Up @@ -509,22 +509,25 @@ void log_frame::UpdateUI()
const std::chrono::time_point tty_timeout = start + 4ms;
const std::chrono::time_point log_timeout = start + 7ms;

// Check TTY logs
while (const u64 size = std::max<s64>(0, g_tty_size.load() - (m_tty_file ? m_tty_file.pos() : 0)))
// Check TTY logs (and try to complete pending work)
for (u64 size{}; !m_tty_buf_stream.view().empty() || (!size && (size = std::max<s64>(0, g_tty_size.load() - (m_tty_file ? m_tty_file.pos() : 0))));)
{
std::string buf;
buf.resize(size);
buf.resize(m_tty_file.read(&buf.front(), buf.size()));
if (!m_tty_buf_stream.view().empty() || m_tty_act->isChecked())
{
std::string buf;
buf.resize(size);
buf.resize(m_tty_file.read(&buf.front(), buf.size()));

// Ignore control characters and greater/equal to 0x80
buf.erase(std::remove_if(buf.begin(), buf.end(), [](s8 c) { return c <= 0x8 || c == 0x7F || (c >= 0xE && c <= 0x1F); }), buf.end());
// Ignore control characters and greater/equal to 0x80
buf.erase(std::remove_if(buf.begin(), buf.end(), [](s8 c) { return c <= 0x8 || c == 0x7F || (c >= 0xE && c <= 0x1F); }), buf.end());

if (!m_tty_buf_stream.view().empty())
{
m_tty_buf_stream.str(buf);
}

if (!buf.empty() && m_tty_act->isChecked())
{
std::stringstream buf_stream;
buf_stream.str(buf);
std::string buf_line;
while (std::getline(buf_stream, buf_line))
while (std::getline(m_tty_buf_stream, buf_line))
{
// save old scroll bar state
QScrollBar* sb = m_tty->verticalScrollBar();
Expand Down Expand Up @@ -582,11 +585,22 @@ void log_frame::UpdateUI()

// set scrollbar to max means auto-scroll
sb->setValue(is_max ? sb->maximum() : sb_pos);

// Limit processing time
if (steady_clock::now() >= tty_timeout) break;
}
}

// Limit processing time
if (steady_clock::now() >= tty_timeout || buf.empty()) break;
if (size)
{
break;
}
}
else
{
// Advance in position without printing
m_tty_file.seek(size, fs::seek_cur);
break;
}
}

const auto font_start_tag = [](const QColor& color) -> const QString { return QStringLiteral("<font color = \"") % color.name() % QStringLiteral("\">"); };
Expand Down
2 changes: 2 additions & 0 deletions rpcs3/rpcs3qt/log_frame.h
Expand Up @@ -7,6 +7,7 @@
#include "find_dialog.h"

#include <memory>
#include <sstream>

#include <QTabWidget>
#include <QPlainTextEdit>
Expand Down Expand Up @@ -54,6 +55,7 @@ private Q_SLOTS:
std::string m_old_log_text;
QString m_old_tty_text;
QString m_log_text;
std::stringstream m_tty_buf_stream;
usz m_log_counter{};
usz m_tty_counter{};
bool m_stack_log{};
Expand Down

0 comments on commit e7a9e9d

Please sign in to comment.