| Summary: | Game controller not detected at first (but detected if hot plugged) | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Eric Ferrot <eric.ferrot> |
| Component: | joystick | Assignee: | Ethan Lee <flibitijibibo> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | philipp.wiesemann |
| Version: | 2.0.3 | ||
| Hardware: | x86_64 | ||
| OS: | Windows 7 | ||
If mappings should be available at initialization then they need to be added before initialization (and not after initialization :). Fixed, thanks! https://hg.libsdl.org/SDL/rev/c59a7e780093 |
Hi! I added a joystick config in the "gamecontrollerdb.txt" mapping file. The joystick is then not detected if already plugged when starting the game. But when first starting the game then plugging the joystick it is working. What is done is the following: Just after the SDL initialization we call "SDL_GameControllerAddMappingsFromFile" SDL.SDL_GameControllerAddMappingsFromFile(mappingsDB); ... and try to Pump controller events early on: public override void BeforeInitialize() { base.BeforeInitialize(); // We want to initialize the controllers ASAP! SDL.SDL_Event[] evt = new SDL.SDL_Event[1]; SDL.SDL_PumpEvents(); // Required to get OSX device events this early. while (SDL.SDL_PeepEvents( evt, 1, SDL.SDL_eventaction.SDL_GETEVENT, SDL.SDL_EventType.SDL_CONTROLLERDEVICEADDED, SDL.SDL_EventType.SDL_CONTROLLERDEVICEADDED ) == 1) { GamePad.INTERNAL_AddInstance(evt[0].cdevice.which); } } It seems the problem is that devices not in SDL's own database (or the environment variable that Steam sets) doesn't get detected properly, so the cdevice event never fires. Could you please have a look? It is the same behavior under Linux and Windows.