Skip to content

Commit

Permalink
Merge pull request #8715 from JosJuice/panic-alert-deadlock
Browse files Browse the repository at this point in the history
DolphinQt: Fix the panic alert deadlock (a.k.a. "Question" issue)
  • Loading branch information
lioncash committed Apr 8, 2020
2 parents 960ba4f + ef77872 commit 9a2d8a9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Source/Core/DolphinQt/Main.cpp
Expand Up @@ -15,6 +15,7 @@
#include <QWidget>

#include "Common/MsgHandler.h"
#include "Common/ScopeGuard.h"

#include "Core/Analytics.h"
#include "Core/Boot/Boot.h"
Expand All @@ -36,7 +37,23 @@
static bool QtMsgAlertHandler(const char* caption, const char* text, bool yes_no,
Common::MsgType style)
{
const bool called_from_cpu_thread = Core::IsCPUThread();

std::optional<bool> r = RunOnObject(QApplication::instance(), [&] {
Common::ScopeGuard scope_guard(&Core::UndeclareAsCPUThread);
if (called_from_cpu_thread)
{
// Temporarily declare this as the CPU thread to avoid getting a deadlock if any DolphinQt
// code calls RunAsCPUThread while the CPU thread is blocked on this function returning.
// Notably, if the panic alert steals focus from RenderWidget, Host::SetRenderFocus gets
// called, which can attempt to use RunAsCPUThread to get us out of exclusive fullscreen.
Core::DeclareAsCPUThread();
}
else
{
scope_guard.Dismiss();
}

ModalMessageBox message_box(QApplication::activeWindow(), Qt::ApplicationModal);
message_box.setWindowTitle(QString::fromUtf8(caption));
message_box.setText(QString::fromUtf8(text));
Expand Down

0 comments on commit 9a2d8a9

Please sign in to comment.