We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2892 - SDL_SYS_JoystickUpdate_XInput clamps the y axis wrongly
Summary: SDL_SYS_JoystickUpdate_XInput clamps the y axis wrongly
Status: RESOLVED WONTFIX
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: HG 2.1
Hardware: x86_64 Windows 7
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords: triage-2.0.4
Depends on:
Blocks:
 
Reported: 2015-02-26 10:50 UTC by gummikana
Modified: 2015-04-07 02:33 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description gummikana 2015-02-26 10:50:20 UTC
SDL_GameControllerGetAxis( joystick, SDL_CONTROLLER_AXIS_LEFTY )  was giving me a range of -32767 to 32767 instead of -32768 to 32767 (which the X axis me). I went investigating and I found the problem:

 SDL_PrivateJoystickAxis( joystick, 1, (Sint16)(-SDL_max(-32767, pXInputState->Gamepad.sThumbLY)) );

(and SDL_PrivateJoystickAxis( joystick, 3, (Sint16)(-SDL_max(-32767, pXInputState->Gamepad.sThumbRY)) );) in SDL_dxjoystick.c


The -32767 is correct. The problem is that pXInputState->Gamepad.sThumbLY is a SHORT meaning it's max positive is 32767, so that clamps the range from -32767 to 32767 and then it's flipped with the -sign. 

The way to fix this is to cast it to int:
SDL_PrivateJoystickAxis( joystick, 1, (Sint16)(-SDL_max(-32767, (int)pXInputState->Gamepad.sThumbLY)) );
Comment 1 Ryan C. Gordon 2015-03-25 00:03:09 UTC
Are you sure this fixes it? If you pass a -32768 here:

SDL_PrivateJoystickAxis( joystick, 1, (Sint16)(-SDL_max(-32767, (int)pXInputState->Gamepad.sThumbLY)) );

That becomes:

SDL_PrivateJoystickAxis( joystick, 1, (Sint16)(-SDL_max(-32767, (int)-32768)) );

And that SDL_max() will return -32767, since that's greater than -32768...so you still end up clamped between -32767 and 32767, even with the explicit cast.

--ryan.
Comment 2 Ryan C. Gordon 2015-04-07 02:33:27 UTC
Going to mark this as WONTFIX; we have to give up a value somewhere, and this one is as  good as any.

--ryan.