Force Feedback Enable Failed when the Program Starts Before the Controller is Connected
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:
- Run the program:
./sdl2hp - Turn on the controller.
- 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.
- Turn on the controller.
- Start the program:
./sdl2hp - Force feedback works.
- Turn off the controller and wait for it to disconnect.
- Turn the controller back on.
- 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
This may only happen with a bluetooth connection.
Controller haptics should use SDL_GameControllerRumble(), which is better supported and more portable for game controllers.