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.
This commit is contained in:
Léo Lam 2016-08-01 17:07:37 +02:00
parent 1ff94c5f2d
commit 53d553d2b0
1 changed files with 3 additions and 0 deletions

View File

@ -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<std::mutex> 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");