Why is SDL_HapticOpenFromJoystick() not working in SDL 2

2.2k Views Asked by At

I'm working on a game that will use SDL 2.0.3 for most of the back-end code (rendering, events, game controllers, etc...). So far I've been able to figure out most of my problems, but this issue doesn't seem to have much information on it.

So my problem is that I'm trying to open an Xbox 360 controller for input and vibration feedback. I've gotten the input to work properly, but when I try to use SDL_HapticOpenFromJoystick() to open the device for vibration, it fails and SDL_GetError() says "Haptic: There are 0 haptic devices availible". Both SDL_NumHaptics() and SDL_JoystickIsHaptic() return 0. I'm using SDL_Init(SDL_INIT_EVERYTHING); to initialize.

I know the Xbox 360 controller itself is able to vibrate, as I have games (not written with SDL) on my Windows 8 laptop that can use the force feedback feature in the controller without issues.

If any more information is needed, I would be glad to provide it.

Relavant Code:

SDL_GameController *myController = NULL;
SDL_Haptic *myHaptic = NULL;

...
[Begin Basic SDL Event Loop]
...

        case SDL_CONTROLLERDEVICEADDED:
            if(!myController)
            {
                myController = SDL_GameControllerOpen(e.cdevice.which);
                debugOut("Controller Connected");
                myHaptic = SDL_HapticOpenFromJoystick(SDL_GameControllerGetJoystick(myController));
                if(myHaptic)
                {
                    debugOut("Haptic Device (i.e. Rumble) Opened");
                }
                else
                {
                    debugOut("Error in opening Haptic Device (i.e. Rumble)");
                    debugOut(SDL_GetError());
                    std::cout << "Number of Haptic Devices: " << SDL_NumHaptics() << std::endl;
                    std::cout << "Controller is Haptic?: " << SDL_JoystickIsHaptic(SDL_GameControllerGetJoystick(myController)) << std::endl;
                }
            }
            else
            {
                debugOut("There is already a controller connected, only one allowed right now...");
            }
            break;

EDIT: I should probably add that I'm using Visual Studio Express 2012...

0

There are 0 best solutions below