Skip to content

Commit

Permalink
DolphinWX: Make UpdateLog() return in a finite time.
Browse files Browse the repository at this point in the history
After fixing the deadlock in dolphin-emu#3006, it is now possible for log
messages to flood in faster than UpdateLog can render them.

This causes it to never return, locking up the gui thread and
filling the windows message queue (which triggers the stack
overflow bug in older versions of Wx)
  • Loading branch information
phire committed Oct 7, 2015
1 parent ec28d7d commit 9728e4a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Source/Core/DolphinWX/LogWindow.cpp
Expand Up @@ -31,6 +31,8 @@

// Milliseconds between msgQueue flushes to wxTextCtrl
#define UPDATETIME 200
// Max size of msgQueue, old messages will be discarded when there are too many.
#define MSGQUEUE_MAX_SIZE 100

CLogWindow::CLogWindow(CFrame *parent, wxWindowID id, const wxPoint& pos,
const wxSize& size, long style, const wxString& name)
Expand Down Expand Up @@ -279,7 +281,11 @@ void CLogWindow::UpdateLog()

m_LogTimer.Stop();

while (true)
// This function runs on the main gui thread, and needs to finish in a finite time otherwise
// the GUI will lock up, which could be an issue if new messages are flooding in faster than
// this function can render them to the screen.
// So we limit this function to processing MSGQUEUE_MAX_SIZE messages each time it's called.
for (int i = 0; i < MSGQUEUE_MAX_SIZE; i++)
{
u8 log_level;
wxString log_msg;
Expand Down Expand Up @@ -339,7 +345,7 @@ void CLogWindow::Log(LogTypes::LOG_LEVELS level, const char *text)
{
std::lock_guard<std::mutex> lk(m_LogSection);

if (msgQueue.size() >= 100)
if (msgQueue.size() >= MSGQUEUE_MAX_SIZE)
msgQueue.pop();

msgQueue.push(std::make_pair(u8(level), StrToWxStr(text)));
Expand Down

0 comments on commit 9728e4a

Please sign in to comment.