From 53d553d2b0b098cd7369fe3ad6e1e83bac20ef33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Mon, 1 Aug 2016 17:07:37 +0200 Subject: [PATCH] WiimoteReal: Fix race between shutdown and FindWiimotes If FindWiimotes() took more time than the UI shutting down, the scanner would try connecting a Wiimote and sending an event to the UI code long after it has shut down, which causes a segfault. This fixes the race by ignoring any found Wiimotes during shutdown. Normally this would have never happened, but it is possible with hidapi since Wiimotes can be connected before Dolphin starts. --- Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp index a1fe2bb9c5..266e67f3e1 100644 --- a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp +++ b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp @@ -500,6 +500,8 @@ void WiimoteScanner::ThreadFunc() Wiimote* found_board = nullptr; backend->FindWiimotes(found_wiimotes, found_board); { + if (!g_real_wiimotes_initialized) + continue; std::lock_guard lk(g_wiimotes_mutex); std::for_each(found_wiimotes.begin(), found_wiimotes.end(), TryToConnectWiimote); if (found_board) @@ -657,6 +659,7 @@ void Stop() // called when the Dolphin app exits void Shutdown() { + g_real_wiimotes_initialized = false; g_wiimote_scanner.StopThread(); NOTICE_LOG(WIIMOTE, "WiimoteReal::Shutdown");