From b9b80191d57385cc2989459555c1ad953b5563d2 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Wed, 9 Sep 2015 12:05:24 +1200 Subject: [PATCH] Fix deadlock with KHR_debug. An KHR_debug callback could end up waiting for a mutex on a thread which calls windows system functions. While this is not expressly forbidden by the standards, it does forbid directy calling windows system functions from a KHR_debug callback. Close enough. --- Source/Core/DolphinWX/LogWindow.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Source/Core/DolphinWX/LogWindow.cpp b/Source/Core/DolphinWX/LogWindow.cpp index e4e8af6407..21ed3c303b 100644 --- a/Source/Core/DolphinWX/LogWindow.cpp +++ b/Source/Core/DolphinWX/LogWindow.cpp @@ -279,10 +279,24 @@ void CLogWindow::UpdateLog() m_LogTimer.Stop(); - std::lock_guard lk(m_LogSection); - while (!msgQueue.empty()) + while (true) { - switch (msgQueue.front().first) + u8 log_level; + wxString log_msg; + + // We can't hold this mutex while calling Wx functions, due to deadlocks + { + std::lock_guard lk(m_LogSection); + + if (msgQueue.empty()) + break; + + log_level = msgQueue.front().first; + log_msg = std::move(msgQueue.front().second); + msgQueue.pop(); + } + + switch (log_level) { case LogTypes::LOG_LEVELS::LERROR: m_Log->SetDefaultStyle(wxTextAttr(*wxRED)); @@ -309,15 +323,13 @@ void CLogWindow::UpdateLog() break; } - if (msgQueue.front().second.size()) + if (log_msg.size()) { int i = m_Log->GetLastPosition(); - m_Log->AppendText(msgQueue.front().second); + m_Log->AppendText(log_msg); // White timestamp m_Log->SetStyle(i, i + 9, wxTextAttr(*wxWHITE)); } - - msgQueue.pop(); } m_LogTimer.Start();