From bb2c50ac94b83848641342bf63d1669e3e7c4c2b Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Wed, 20 Jan 2021 17:23:56 -0600 Subject: [PATCH] WiimoteReal: Fix crash on real Wii Remote disconnect on Windows caused by dangling pointer. --- Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp index 005be23c76..a44bcfed2b 100644 --- a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp +++ b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp @@ -916,7 +916,9 @@ static void TryToConnectBalanceBoard(std::unique_ptr wm) static void HandleWiimoteDisconnect(int index) { Core::RunAsCPUThread([index] { - g_wiimotes[index] = nullptr; + // The Wii Remote object must exist through the call to UpdateSource + // to prevent WiimoteDevice from having a dangling HIDWiimote pointer. + const auto temp_real_wiimote = std::move(g_wiimotes[index]); WiimoteCommon::UpdateSource(index); }); }