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())
{
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();