SDL icon indicating copy to clipboard operation
SDL copied to clipboard

Force Feedback Enable Failed when the Program Starts Before the Controller is Connected

Open orbea opened this issue 3 years ago • 1 comments

OS: Gentoo linux: 5.15.64 SDL: 2.24.0 Controllers: Sony PLAYSTATION(R)3 Controller + 8bitdo SN30 Pro+ xpadneo: https://github.com/atar-axis/xpadneo/commit/48f4b119fdef9479d5e45056dc7a234e8959af0d

With a program that supports hotplugging the controllers the force feedback will fail if the program is started before the controller is connected for the first time.

Force Feedback Enable Failed: Haptic: Invalid haptic device identifier

This can be reproduced with this test program. sdl2hp.c.txt

It can be compiled with:

cc sdl2hp.c -std=c99 $(sdl2-config --cflags --libs) -o sdl2hp

To reproduce:

  1. Run the program: ./sdl2hp
  2. Turn on the controller.
  3. The controller's force feedback fails in the currently running program.
$ ./sdl2hp
Joystick Connected: Xbox 360 Controller
	Instance ID: 0, Player: 0
Force Feedback Enable Failed: Haptic: Invalid haptic device identifier
Ports: 1 0 0 0

However if the controller is started before the program the force feedback will work as expected when the controller disconnects and then reconnects.

  1. Turn on the controller.
  2. Start the program: ./sdl2hp
  3. Force feedback works.
  4. Turn off the controller and wait for it to disconnect.
  5. Turn the controller back on.
  6. Force feedback still works.
$ ./sdl2hp
Joystick Connected: Xbox 360 Controller
	Instance ID: 0, Player: 0
Force Feedback Enabled
Ports: 1 0 0 0

Instance ID: 0
Joystick 0 Disconnected
Ports: 0 0 0 0

Joystick Connected: Xbox 360 Controller
	Instance ID: 1, Player: 0
Force Feedback Enabled
Ports: 1 0 0 0

For reference there is a SDL2 hotplug example here: https://github.com/carmiker/sdl2-hotplug-example

orbea avatar Sep 18 '22 01:09 orbea

This may only happen with a bluetooth connection.

orbea avatar Sep 18 '22 16:09 orbea

Controller haptics should use SDL_GameControllerRumble(), which is better supported and more portable for game controllers.

slouken avatar Nov 07 '23 16:11 slouken