From e14c54b846f4762afb6f7116cd0146c80d0b6534 Mon Sep 17 00:00:00 2001 From: capitalistspz Date: Fri, 27 Sep 2024 00:15:09 +0100 Subject: [PATCH] Fix a crash from writing to a disconnected device --- src/input/api/Wiimote/WiimoteControllerProvider.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/input/api/Wiimote/WiimoteControllerProvider.cpp b/src/input/api/Wiimote/WiimoteControllerProvider.cpp index 830d987e..2444fa42 100644 --- a/src/input/api/Wiimote/WiimoteControllerProvider.cpp +++ b/src/input/api/Wiimote/WiimoteControllerProvider.cpp @@ -955,14 +955,17 @@ void WiimoteControllerProvider::writer_thread() if (index != (size_t)-1 && !data.empty()) { auto& wiimote = m_wiimotes[index]; + if (!wiimote.device) + continue; if (wiimote.rumble) data[1] |= 1; if (!wiimote.device->write_data(data)) + { wiimote.device.reset(); - if (wiimote.device) - wiimote.data_ts = std::chrono::high_resolution_clock::now(); - else wiimote.rumble = false; + } + else + wiimote.data_ts = std::chrono::high_resolution_clock::now(); } device_lock.unlock();