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 - Game controller not detected at first (but detected if hot plugged)
Summary: Game controller not detected at first (but detected if hot plugged)
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: 2.0.3
Hardware: x86_64 Windows 7
: P2 normal
Assignee: Ethan Lee
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-09-24 21:13 UTC by Eric Ferrot
Modified: 2016-03-07 15:50 UTC (History)
1 user (show)

See Also:


Attachments

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