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 3129

Summary: Game controller not detected at first (but detected if hot plugged)
Product: SDL Reporter: Eric Ferrot <eric.ferrot>
Component: joystickAssignee: 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   

Description Eric Ferrot 2015-09-24 21:13:48 UTC
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.
Comment 1 Philipp Wiesemann 2015-12-08 19:32:39 UTC
If mappings should be available at initialization then they need to be added before initialization (and not after initialization :).
Comment 2 Sam Lantinga 2016-03-07 15:50:15 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/c59a7e780093