From 72f7225ec2710e0317d360e9d934374ae895df82 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Thu, 1 Jun 2023 23:18:35 +1000 Subject: [PATCH] Qt: Fix ClearBindStateFromSource() executing on wrong thread --- src/duckstation-qt/mainwindow.cpp | 2 +- src/duckstation-qt/qthost.cpp | 11 +++++++++++ src/duckstation-qt/qthost.h | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index e4655c69d..c37379b82 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -690,7 +690,7 @@ void MainWindow::onApplicationStateChanged(Qt::ApplicationState state) // Clear the state of all keyboard binds. // That way, if we had a key held down, and lost focus, the bind won't be stuck enabled because we never // got the key release message, because it happened in another window which "stole" the event. - InputManager::ClearBindStateFromSource(InputManager::MakeHostKeyboardKey(0)); + g_emu_thread->clearInputBindStateFromSource(InputManager::MakeHostKeyboardKey(0)); } else { diff --git a/src/duckstation-qt/qthost.cpp b/src/duckstation-qt/qthost.cpp index 320f3671e..f02892fef 100644 --- a/src/duckstation-qt/qthost.cpp +++ b/src/duckstation-qt/qthost.cpp @@ -1065,6 +1065,17 @@ void EmuThread::reloadPostProcessingShaders() System::ReloadPostProcessingShaders(); } +void EmuThread::clearInputBindStateFromSource(InputBindingKey key) +{ + if (!isOnThread()) + { + QMetaObject::invokeMethod(this, "clearInputBindStateFromSource", Qt::QueuedConnection, Q_ARG(InputBindingKey, key)); + return; + } + + InputManager::ClearBindStateFromSource(key); +} + void EmuThread::runOnEmuThread(std::function callback) { callback(); diff --git a/src/duckstation-qt/qthost.h b/src/duckstation-qt/qthost.h index d45be2460..c57f89be6 100644 --- a/src/duckstation-qt/qthost.h +++ b/src/duckstation-qt/qthost.h @@ -187,6 +187,7 @@ public Q_SLOTS: void setCheatEnabled(quint32 index, bool enabled); void applyCheat(quint32 index); void reloadPostProcessingShaders(); + void clearInputBindStateFromSource(InputBindingKey key); private Q_SLOTS: void stopInThread();