From dad82aa1eb0914ee7dcafcb7a4f7d572693dd33a Mon Sep 17 00:00:00 2001 From: Peter Tissen Date: Wed, 2 Apr 2014 17:57:50 +0200 Subject: [PATCH] Gui logging in main thread Do the logging to the GUI log element in the main thread. Not doing this causes issues with the GTK backend of wxWidgets. Plus it's just common sense to try to limit gui calls to one thread. --- rpcs3/Gui/ConLog.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/rpcs3/Gui/ConLog.cpp b/rpcs3/Gui/ConLog.cpp index 094c91c2a7..4bb1c7a252 100644 --- a/rpcs3/Gui/ConLog.cpp +++ b/rpcs3/Gui/ConLog.cpp @@ -212,19 +212,24 @@ void LogFrame::Task() const LogPacket item = LogBuffer.Pop(); - while(m_log.GetItemCount() > max_item_count) + wxListView& m_log = this->m_log; //makes m_log capturable by the lambda + //queue adding the log message to the gui element in the main thread + wxTheApp->GetTopWindow()->GetEventHandler()->CallAfter([item, &m_log]() { - m_log.DeleteItem(0); - wxThread::Yield(); - } + while (m_log.GetItemCount() > max_item_count) + { + m_log.DeleteItem(0); + wxThread::Yield(); + } - const int cur_item = m_log.GetItemCount(); + const int cur_item = m_log.GetItemCount(); - m_log.InsertItem(cur_item, fmt::FromUTF8(item.m_prefix)); - m_log.SetItem(cur_item, 1, fmt::FromUTF8(item.m_text)); - m_log.SetItemTextColour(cur_item, fmt::FromUTF8(item.m_colour)); - m_log.SetColumnWidth(0, -1); // crashes on exit - m_log.SetColumnWidth(1, -1); + m_log.InsertItem(cur_item, fmt::FromUTF8(item.m_prefix)); + m_log.SetItem(cur_item, 1, fmt::FromUTF8(item.m_text)); + m_log.SetItemTextColour(cur_item, fmt::FromUTF8(item.m_colour)); + m_log.SetColumnWidth(0, -1); + m_log.SetColumnWidth(1, -1); + }); #ifdef _WIN32 ::SendMessage((HWND)m_log.GetHWND(), WM_VSCROLL, SB_BOTTOM, 0);