Joystick axis problem and crash

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:
[source lang=“cpp”]
if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) != 0 )
{
std::cout << "Unable to initialize SDL: " << SDL_GetError() << std::endl;
return false;
}
[/source]

Here’s how I setup joystick support:
[source lang=“cpp”]
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.");

[/source]

Here’s how I handle events:
[source lang=“cpp”]
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;
	}
}

[/source]

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 :slight_smile:

Which version of SDL is it? Can you post the backtrace?

Jonny DOn Thu, Jun 24, 2010 at 1:19 AM, yezu wrote:

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:
[source lang=“cpp”]
if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) != 0 )
{
std::cout << "Unable to initialize SDL: " << SDL_GetError() << std::endl;
return false;
}
[/source]

Here’s how I setup joystick support:
[source lang=“cpp”]
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.”);
[/source]

Here’s how I handle events:
[source lang=“cpp”]
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;
}
}
[/source]

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 [image: Smile]


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

According to my package manager I use 1.2.14-4. The one that is currently packaged in the Fedora 13 repository.

The backtrace:

Code:
#0 0x0084749d in ?? () from /usr/lib/libSDL-1.2.so.0
#1 0x0081dc50 in SDL_JoystickUpdate () from /usr/lib/libSDL-1.2.so.0
#2 0x007f62de in SDL_PumpEvents () from /usr/lib/libSDL-1.2.so.0
#3 0x007f6748 in SDL_PollEvent () from /usr/lib/libSDL-1.2.so.0
#4 0x08060081 in MenuState::gatherInput (this=0x83c6e68)
at …/src/Menu/MenuState.cpp:250
#5 0x0805fc21 in MenuState::update (this=0x83c6e68, frame=0.479999989)
at …/src/Menu/MenuState.cpp:224
#6 0x080617df in MenuManager::executeMachineState (this=0x8276888)
at …/src/Menu/MenuManager.cpp:169
#7 0x08060f5b in MenuManager::run (this=0x8276888, frame=0.479999989)
at …/src/Menu/MenuManager.cpp:32
#8 0x08070c71 in Application::executeMachineState (this=0x809e350)
at …/src/Application/Application.cpp:259
#9 0x08070aed in Application::run (this=0x809e350)
at …/src/Application/Application.cpp:204
#10 0x080593b2 in main () at …/src/PAJ-TUN.cpp:103

Those question marks are probably SDL_SYS_JoystickUpdate(). If you feel
comfortable, you could rebuild SDL from source with debug symbols. Could
you attach a minimal program’s source which reproduces the crash?

Jonny DOn Sat, Jun 26, 2010 at 5:19 AM, yezu wrote:

According to my package manager I use 1.2.14-4. The one that is currently
packaged in the Fedora 13 repository.

The backtrace:

Code:

#0 0x0084749d in ?? () from /usr/lib/libSDL-1.2.so.0
#1 0x0081dc50 in SDL_JoystickUpdate () from /usr/lib/libSDL-1.2.so.0
#2 0x007f62de in SDL_PumpEvents () from /usr/lib/libSDL-1.2.so.0
#3 0x007f6748 in SDL_PollEvent () from /usr/lib/libSDL-1.2.so.0
#4 0x08060081 in MenuState::gatherInput (this=0x83c6e68)
at …/src/Menu/MenuState.cpp:250
#5 0x0805fc21 in MenuState::update (this=0x83c6e68, frame=0.479999989)
at …/src/Menu/MenuState.cpp:224
#6 0x080617df in MenuManager::executeMachineState (this=0x8276888)
at …/src/Menu/MenuManager.cpp:169
#7 0x08060f5b in MenuManager::run (this=0x8276888, frame=0.479999989)
at …/src/Menu/MenuManager.cpp:32
#8 0x08070c71 in Application::executeMachineState (this=0x809e350)
at …/src/Application/Application.cpp:259
#9 0x08070aed in Application::run (this=0x809e350)
at …/src/Application/Application.cpp:204
#10 0x080593b2 in main () at …/src/PAJ-TUN.cpp:103


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Have you tried the latest snapshot?
http://www.libsdl.org/tmp/SDL-1.2.zipOn Thu, Jun 24, 2010 at 1:19 AM, yezu wrote:

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:
[source lang=“cpp”]
if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) != 0 )
{
std::cout << "Unable to initialize SDL: " << SDL_GetError() << std::endl;
return false;
}
[/source]

Here’s how I setup joystick support:
[source lang=“cpp”]
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.”);
[/source]

Here’s how I handle events:
[source lang=“cpp”]
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;
}
}
[/source]

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 [image: Smile]


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and President, Galaxy Gameworks LLC

Why not just install the debug package for it? I assume Fedora has those? on OpenSUSE there is a debug rpm for each package which adds the symbols, and gdb picks up on that.On 06/26/2010 06:48 AM, Jonathan Dearborn wrote:

Those question marks are probably SDL_SYS_JoystickUpdate(). If you feel
comfortable, you could rebuild SDL from source with debug symbols.
Could you attach a minimal program’s source which reproduces the crash?

Jonny D

On Sat, Jun 26, 2010 at 5:19 AM, yezu <yezu666 at gmail.com <mailto:yezu666 at gmail.com>> wrote:

According to my package manager I use 1.2.14-4. The one that is
currently packaged in the Fedora 13 repository.

The backtrace:



Code:	

#0  0x0084749d in ?? () from /usr/lib/libSDL-1.2.so.0
#1  0x0081dc50 in SDL_JoystickUpdate () from /usr/lib/libSDL-1.2.so.0
#2  0x007f62de in SDL_PumpEvents () from /usr/lib/libSDL-1.2.so.0
#3  0x007f6748 in SDL_PollEvent () from /usr/lib/libSDL-1.2.so.0
#4  0x08060081 in MenuState::gatherInput (this=0x83c6e68)
    at ../src/Menu/MenuState.cpp:250
#5  0x0805fc21 in MenuState::update (this=0x83c6e68, frame=0.479999989)
    at ../src/Menu/MenuState.cpp:224
#6  0x080617df in MenuManager::executeMachineState (this=0x8276888)
    at ../src/Menu/MenuManager.cpp:169
#7  0x08060f5b in MenuManager::run (this=0x8276888, frame=0.479999989)
    at ../src/Menu/MenuManager.cpp:32
#8  0x08070c71 in Application::executeMachineState (this=0x809e350)
    at ../src/Application/Application.cpp:259
#9  0x08070aed in Application::run (this=0x809e350)
    at ../src/Application/Application.cpp:204
#10 0x080593b2 in main () at ../src/PAJ-TUN.cpp:103	


_______________________________________________
SDL mailing list
SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


LordHavoc
Author of DarkPlaces Quake1 engine - http://icculus.org/twilight/darkplaces
Co-designer of Nexuiz - http://alientrap.org/nexuiz
"War does not prove who is right, it proves who is left." - Unknown
"Any sufficiently advanced technology is indistinguishable from a rigged demo." - James Klass
"A game is a series of interesting choices." - Sid Meier

Have you been able to reproduce the crash with “testjoystick” from the SDL
source distribution?

The first step in diagnosing this kind of problem should be attempting to
reproduce a bug with tests from the SDL source distribution.

If you cannot reproduce the bug, it’s more likely that the bug is in your
program, in which case I advise you to proceed with diagnostics using
valgrind or a similar tool.On Thu, Jun 24, 2010 at 4:19 AM, yezu wrote:

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:
[source lang=“cpp”]
if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) != 0 )
{
std::cout << "Unable to initialize SDL: " << SDL_GetError() << std::endl;
return false;
}
[/source]

Here’s how I setup joystick support:
[source lang=“cpp”]
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.”);
[/source]

Here’s how I handle events:
[source lang=“cpp”]
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;
}
}
[/source]

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 [image: Smile]


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


http://codebad.com/