diff --git a/Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp b/Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp index 206c11ab64..91bd1bec6c 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp +++ b/Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp @@ -560,7 +560,7 @@ bool Wiimote::IsConnected() const void _IOWakeup(HANDLE &dev_handle, OVERLAPPED &hid_overlap_read) { - CancelIoEx(dev_handle, &hid_overlap_read); + SetEvent(hid_overlap_read.hEvent); } // positive = read packet @@ -582,26 +582,22 @@ int _IORead(HANDLE &dev_handle, OVERLAPPED &hid_overlap_read, u8* buf, int index if (ERROR_IO_PENDING == read_err) { auto const wait_result = WaitForSingleObject(hid_overlap_read.hEvent, INFINITE); - if (WAIT_TIMEOUT == wait_result) - { - CancelIo(dev_handle); - } - else if (WAIT_FAILED == wait_result) + + // In case the event was signalled by _IOWakeup before the read completed, cancel it. + CancelIo(dev_handle); + + if (WAIT_FAILED == wait_result) { WARN_LOG(WIIMOTE, "A wait error occurred on reading from Wiimote %i.", index + 1); - CancelIo(dev_handle); } - if (!GetOverlappedResult(dev_handle, &hid_overlap_read, &bytes, TRUE)) + if (!GetOverlappedResult(dev_handle, &hid_overlap_read, &bytes, FALSE)) { auto const overlapped_err = GetLastError(); if (ERROR_OPERATION_ABORTED == overlapped_err) { - /* - if (buf[1] != 0) - WARN_LOG(WIIMOTE, "Packet ignored. This may indicate a problem."); - */ + // It was. return -1; }