1
0
Fork 0

jsWindows: fail gracefully when joyGetDevCaps() returns undocumented values

According to Pfeffer's report[1] and many other messages on the
Internet, joyGetDevCaps() can return the (so far) undocumented value
165, which some say is JOYERR_PARMS. Since this is a valid return code
for joyGetPosEx() (not joyGetDevCaps()!), handle a few return codes from
that function too, and don't throw an exception when joyGetDevCaps()'s
return value is not one of the documented ones (we simply can't trust
its documentation).

[1] https://sourceforge.net/p/flightgear/mailman/message/36657149/
This commit is contained in:
Florent Rougon 2019-05-04 08:43:40 +02:00
parent 7db06300c0
commit df352346ad

View file

@ -51,12 +51,20 @@ static std::string joyGetDevCaps_errorString(MMRESULT errorCode)
"invalid";
case MMSYSERR_INVALPARAM:
return "invalid parameter passed to joyGetDevCaps()";
// joyGetDevCaps() appears to return undocumented values, see
// https://sourceforge.net/p/flightgear/mailman/message/36657149/
case MMSYSERR_BADDEVICEID: // fallthrough
case JOYERR_PARMS:
return "invalid joystick identifier";
case JOYERR_UNPLUGGED:
return "joystick not connected to the system";
case JOYERR_NOERROR:
return "no error";
default:
throw sg_exception(
"Unexpected value passed to joyGetDevCaps_errorString(): "
+ std::to_string(errorCode));
// Don't throw an exception, since joyGetDevCaps()'s documentation isn't
// correct (we can't be sure to have covered all possible return values).
return "unexpected value passed to joyGetDevCaps_errorString(): "
+ std::to_string(errorCode);
}
throw sg_exception("This code path should be unreachable; value "