Original Post
Hello!
I've been trying to add joystick/joypad support to my app. However I have ran into some problems.
I test this with a "dualshock" type of gamepad. All of the buttons work correctly. The analogues and the d-pad are recognized as axes.
The problem is:
When I use any of the analogue sticks the axis is always returned as 0.
When I use the D-pad the app exits.
GDB says that the crash appears somewhere deep within SDL.
I call SDL_PollEvent(),
which in turn calls SDL_PumpEvents(),
which in turn calls SDL_JoystickUpdate()
and then the app. exits with a Segmentation fault.
I initialize SDL with:
Here's how I setup joystick support:
Here's how I handle events:
I couldn't find anywhere anything useful. Does anyone have any idea what I am doing wrong?
I'm running Fedora 13 i386.
thanks a lot :)
I've been trying to add joystick/joypad support to my app. However I have ran into some problems.
I test this with a "dualshock" type of gamepad. All of the buttons work correctly. The analogues and the d-pad are recognized as axes.
The problem is:
When I use any of the analogue sticks the axis is always returned as 0.
When I use the D-pad the app exits.
GDB says that the crash appears somewhere deep within SDL.
I call SDL_PollEvent(),
which in turn calls SDL_PumpEvents(),
which in turn calls SDL_JoystickUpdate()
and then the app. exits with a Segmentation fault.
I initialize SDL with:
if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) != 0 ) { std::cout << "Unable to initialize SDL: " << SDL_GetError() << std::endl; return false; }Here's how I setup joystick support:
bool joyok = true; if(SDL_JoystickEventState(SDL_ENABLE) != SDL_ENABLE) { Console::print("Cannot enable Joystick event polling!"); joyok = false; } if( SDL_NumJoysticks() < 1 ) { Console::print("No Joysticks!"); joyok = false; } else joystick = SDL_JoystickOpen(0); if(joystick == 0x0 && joyok) Console::print("Joystick failed!"); if(joyok) Console::print("Joystick enabled."); else Console::print("Joystick enabling failed.");Here's how I handle events:
SDL_Event Event; while(SDL_PollEvent(&Event)) { switch(Event.type) { case SDL_JOYAXISMOTION: { JoystickInput::getAxisAction(Event.jaxis); std::string o = "Axis: " + Utilities::intToStr(Event.jaxis.axis); Console::print(o); } break; case SDL_JOYBUTTONDOWN: { JoystickInput::getMenuAction(Event.jbutton.button); std::string o = "Button: " + Utilities::intToStr(Event.jbutton.button); Console::print(o); } break; } }I couldn't find anywhere anything useful. Does anyone have any idea what I am doing wrong?
I'm running Fedora 13 i386.
thanks a lot :)