Fix a crash from writing to a disconnected device

This commit is contained in:
capitalistspz 2024-09-27 00:15:09 +01:00
parent 55e240339c
commit e14c54b846

View file

@ -955,14 +955,17 @@ void WiimoteControllerProvider::writer_thread()
if (index != (size_t)-1 && !data.empty()) if (index != (size_t)-1 && !data.empty())
{ {
auto& wiimote = m_wiimotes[index]; auto& wiimote = m_wiimotes[index];
if (!wiimote.device)
continue;
if (wiimote.rumble) if (wiimote.rumble)
data[1] |= 1; data[1] |= 1;
if (!wiimote.device->write_data(data)) if (!wiimote.device->write_data(data))
{
wiimote.device.reset(); wiimote.device.reset();
if (wiimote.device)
wiimote.data_ts = std::chrono::high_resolution_clock::now();
else
wiimote.rumble = false; wiimote.rumble = false;
}
else
wiimote.data_ts = std::chrono::high_resolution_clock::now();
} }
device_lock.unlock(); device_lock.unlock();