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 - SDL_GameControllerAddMapping update problem
Summary: SDL_GameControllerAddMapping update problem
Status: NEW
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: 2.0.9
Hardware: x86_64 Linux
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-02-15 18:35 UTC by Bob Ombo
Modified: 2019-02-26 17:34 UTC (History)
1 user (show)

See Also:


Attachments
Example code for SDL_GameControllerAddMapping() (4.50 KB, text/x-csrc)
2019-02-15 18:35 UTC, Bob Ombo
Details

Note You need to log in before you can comment on or make changes to this bug.
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.