Prevent crash on joystick disconnect on Windows
@@ -184,11 +184,15 @@ class DirectInputDevice(base.Device):
events = (dinput.DIDEVICEOBJECTDATA * 64)()
n_events = win32.DWORD(len(events))
+ try:
self._device.GetDeviceData(ctypes.sizeof(dinput.DIDEVICEOBJECTDATA),
ctypes.cast(ctypes.pointer(events),
dinput.LPDIDEVICEOBJECTDATA),
ctypes.byref(n_events),
0)
+ except OSError:
+ return
+
for event in events[:n_events.value]:
index = event.dwOfs // 4
self.controls[index].value = event.dwData
