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 2950

Summary: wrong axes values are set on joystick initialization
Product: SDL Reporter: Edward Rudd <urkle>
Component: joystickAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 2.0   
Hardware: All   
OS: Linux   

Description Edward Rudd 2015-04-17 19:19:14 UTC
Device: Logitech Rumble Gamepad F510 in Xinput mode.

Upon opening the joystick the values of the axes are queried via PollAllValues are not actually set on the device all the time.

This can easily be seen in the testjoystick or testgamecontroller test programs,as the testjoystick shows all axes in the center until one 'tickles' the triggers., and the testgamecontroller will show the triggers as 'on' until on 'tickles' the triggers.


Upon further research the culprit is the SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS hint. In the default value events are ignored until there is an active window, Thus in cases where the joystick system is initialized and controllers opened before the initial window is created & focuses, the initial values will be incorrect.
Comment 1 Edward Rudd 2015-04-20 04:43:05 UTC
Here is my current workaround in the game I'm working on porting..

SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
SDL_GameController* gamepad = SDL_GameControllerOpen(index);
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "0");
Comment 2 Sam Lantinga 2016-10-08 00:15:14 UTC
Can you try this again in with the latest from Mercurial? I think I may have fixed this today.
Comment 3 Sam Lantinga 2017-08-13 00:22:48 UTC
Edward, can you please respond?
Comment 4 Sam Lantinga 2017-08-13 00:42:17 UTC
This is fixed, thanks!
https://hg.libsdl.org/SDL/rev/0302e7e91db7