From 716c54217a1109378b33c58e2b9eca71c4075d1b Mon Sep 17 00:00:00 2001
From: "Admiral H. Curtiss" <pikachu025@gmail.com>
Date: Sun, 21 Jun 2015 14:22:07 +0200
Subject: [PATCH] WiimoteReal: Make sure that Wiimote thread isn't already
 running before starting it.

This fixes a crash when switching a Wiimote's internal slot or type in the Dolphin config.
---
 Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp
index 4967032f46..ab8dcc8460 100644
--- a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp
+++ b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp
@@ -485,9 +485,12 @@ void WiimoteScanner::ThreadFunc()
 
 bool Wiimote::Connect()
 {
-	m_thread_ready.store(false);
-	StartThread();
-	WaitReady();
+	if (!m_run_thread.load())
+	{
+		m_thread_ready.store(false);
+		StartThread();
+		WaitReady();
+	}
 	return IsConnected();
 }