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 4505

Summary: SDL_GameControllerAddMapping update problem
Product: SDL Reporter: Bob Ombo <bombo>
Component: joystickAssignee: Sam Lantinga <slouken>
Status: NEW --- QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: bombo
Version: 2.0.9   
Hardware: x86_64   
OS: Linux   
Attachments: Example code for SDL_GameControllerAddMapping()

Description Bob Ombo 2019-02-15 18:35:39 UTC
Created attachment 3625 [details]
Example code for SDL_GameControllerAddMapping()

The map doesn't seem to survive a second SDL_GameControllerAddMapping()

SDL_GameControllerAddMapping
const char *mappingString="..."

// first add my map
amr=SDL_GameControllerAddMapping(mappingString);
// (added) everything works as expected!

// just do it a second time
amr=SDL_GameControllerAddMapping(mappingString);
// (updated) now some axis and buttons are wrong

(Complete example attached.)
Comment 1 Bob Ombo 2019-02-15 18:55:48 UTC
Actually the same happens if i just call 
SDL_GameControllerAddMapping()
ONCE, then just close and reopen the controller:

SDL_GameControllerClose(controller);
controller=SDL_GameControllerOpen(0);

The map is saved:
SDL_GameControllerMapping(controller)
does show the correct map.

Just some axis and buttons are wrong now.
Comment 2 Bob Ombo 2019-02-26 17:34:58 UTC
OK i finally found out what the problem was:

1. The mapping was wrong
2. The controller did work because it didn't use the wrong map, but default mapping instead

If you do

controller=SDL_GameControllerOpen(0);
SDL_GameControllerAddMapping(mappingString);

the mapping will not be active!

So always do it the other way round:

SDL_GameControllerAddMapping(mappingString);
controller=SDL_GameControllerOpen(0);

So unless this is a bug, and SDL_GameControllerAddMapping should work even
when the controller is opened already, this bug can be closed.