Emulator Issues #6071
closedWiimote packet loss on Windows [with proposed patch]
0%
Description
While developing my sf.net/projects/wiimotecontrol application, I
discovered a bug in Dolphin's WiimoteReal/IOWin.cpp file.
This bug could lead to ignoring packets from the Wiimote, which I
actually experienced indeed. Losing a packet in which the button
bitmask changes, for example due to releasing a button, can be
particularly nasty.
The Wiimote sends a packet when pressing a button, and when releasing
a button. In between this time, Dolphin repeats the last packet (i.e.,
the "button press packet"). If we then miss the "button release
packet", Dolphin keeps repeating the "button press packet" until it
receives a new packet. If indeed such a packet is lost, it causes my
Wiimote Control application to behave as if the last-pressed button
(or buttons) is/are still held down.
I imagine this also happens on the computers of Dolphin users, perhaps
far less often (maybe that's why it hasn't been fixed yet?), for some
reason I haven't looked into.
The technical issue is that after calling CancelIo(), IOWin.cpp does
NOT call GetOverlappedResult(). This means a packet may be lost (in
fact there's even a WARN_LOG() call for that).
To see why calling GetOverlappedResult() after calling CancelIo() is
necessary, I quote this excerpt from 'fixed.patch':
// We must make sure the attempt at cancellation has
// completed, by calling GetOverlappedResult(). We must
// still determine the result of the operation. Did the
// cancellation succeed, or did the packet still get
// through?
If indeed the packet still got through after calling CancelIo(),
Dolphin should handle it, and not ignore it.
I have attached a binary (plus a patch one can use to re-create this
binary; feel free to do so). The binary is the Wiimote Control program
with modifications so that the bug can be revealed reasonably quickly
if one keeps tapping a button on the Wiimote (might need to retry it a
few times).
In total I've attached two patches, one ('packet loss test.patch') to
create the Wiimote Control test case binary with, and the other
contains the proposed solution ('fixed.patch') for Dolphin.
Cheers