We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 575 - Use of digital pad of a DualShock(in analog mode) crash SDL Application
Summary: Use of digital pad of a DualShock(in analog mode) crash SDL Application
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: 1.2.13
Hardware: x86 Linux
: P2 critical
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
: 786 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-04-23 02:14 UTC by Shad
Modified: 2009-09-28 17:39 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Shad 2008-04-23 02:14:14 UTC
- Linux distribution: Mandriva 2008.1
- Machine type: Core 2 Duo 64-bit
- Applications tested: mupen64plus (1.0 -> svn)[64bits], sdlmame (0.124)[64bits], zsnes (1.51)[32bits]

I got a dual shock controller plugged via a "MP-8866 Dual USB Joypad". In analog mode, both analog sticks, all button and digital axis are recognised by the system.
SDL Applications recognise analog stick and all button without problem but when I try to set (in config screens) or use (within a game) a direction of the digital pad, the application segfault.
In digital mode, the digital pad work flawlesly.

According to the joystick configuration panel of kde:
- in digital mode, the digital pad is binded on axis 1(x) and 2(y) (and 
can return "-32767", "0" or "32767" values) the analog sticks are 
inactive.
- In Analog Mode, the digital pad is binded on axis 5(x) and 6(y) (and 
can return "-32767", "0" or "32767" values). The left analog stick is 
binded on axis 1(x) and 2(y) and right one is binded on axis 3(x) and 4
(y)(and can both return all value between "-32767" and "32767").
Comment 1 Sam Lantinga 2009-09-21 01:06:21 UTC
Can you run your program under gdb to get a stack trace?
Comment 2 Bryan Hitchcock 2009-09-23 10:57:30 UTC
9/23 10:55 am - Email sent to shadow.w@gmail.com requesting reply to Sam's query.
Comment 3 Shad 2009-09-23 14:12:47 UTC
here is what I got using mupen64plus:

[shad@azrael ~]$ gdb mupen64plus
GNU gdb 6.8-7mdv2010.0 (Mandriva Linux release 2010.0)
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-mandriva-linux-gnu"...
(gdb) run
Starting program: /usr/bin/mupen64plus
[Thread debugging using libthread_db enabled]
[New Thread 0x7f5ef0154750 (LWP 8779)]
 __  __                         __   _  _   ____  _
|  \/  |_   _ _ __   ___ _ __  / /_ | || | |  _ \| |_   _ ___
| |\/| | | | | '_ \ / _ \ '_ \| '_ \| || |_| |_) | | | | / __|
| |  | | |_| | |_) |  __/ | | | (_) |__   _|  __/| | |_| \__ \
|_|  |_|\__,_| .__/ \___|_| |_|\___/   |_| |_|   |_|\__,_|___/
             |_|         http://code.google.com/p/mupen64plus/
Version 1.5-development

Config Dir:  /home/shad/.mupen64plus/
Install Dir: /usr/share/mupen64plus/
Plugin Dir:  /usr/share/mupen64plus/plugins/

[New Thread 0x7f5ed834a910 (LWP 8790)]
Rescanning rom cache.
Scanning... /mnt/emulation/Nintendo/N64/roms/
Rom cache up to date. 335 ROMs.
Detaching after fork from child process 8791.
[New Thread 0x7f5ed7874910 (LWP 8796)]

---------
Here I open the input configuration dialog then press a direction on the digital pad
---------

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7f5ed7874910 (LWP 8796)]
0x00007f5eef37e2dc in EV_HandleEvents (joystick=0x4ae0c10) at src/joystick/linux/SDL_sysjoystick.c:945
945                             hats = SDL_joylist[stick->index].map->hatmap+hat;
(gdb) bt
#0  0x00007f5eef37e2dc in EV_HandleEvents (joystick=0x4ae0c10) at src/joystick/linux/SDL_sysjoystick.c:945
#1  0x00007f5eef37f2c7 in SDL_SYS_JoystickUpdate (joystick=0x0) at src/joystick/linux/SDL_sysjoystick.c:1141
#2  0x00007f5eef34c09d in SDL_JoystickUpdate () at src/joystick/SDL_joystick.c:540
#3  0x00007f5ee5c1e8ca in ?? () from /usr/share/mupen64plus/plugins/blight_input.so
#4  0x00007f5eef325415 in SDL_RunThread (data=0x4b0a040) at src/thread/SDL_thread.c:202
#5  0x00007f5eef37d819 in RunThread (data=0x0) at src/thread/pthread/SDL_systhread.c:47
#6  0x00007f5eebef37cd in start_thread () from /lib64/libpthread.so.0
#7  0x00007f5eebc6637d in clone () from /lib64/libc.so.6
#8  0x0000000000000000 in ?? ()
Comment 4 Sam Lantinga 2009-09-26 04:58:50 UTC
What are stick->index and SDL_joylist[stick->index].map ?

Is there any chance I could borrow the joystick for a few days to test with?  Or can I remote log into your system for debugging?
Comment 5 Shad 2009-09-26 13:16:09 UTC
(In reply to comment #4)
> What are stick->index and SDL_joylist[stick->index].map ?

I tried to run GDB with a smaller test program (found here http://www.gnurou.org/writing/linuxmag/sdl/partie2) 
I've put a breakpoint at line 1001 and 1098 before HandleHat is called and at 921, the beinning of HandleHat
[...]
Breakpoint 2, EV_HandleEvents (joystick=0x1d2b530) at src/joystick/linux/SDL_sysjoystick.c:1098
1098                                            code -= ABS_HAT0X;
(gdb) print joystick
$1 = (SDL_Joystick *) 0xd20450
(gdb) print code
$2 = 16
(gdb) print i
$3 = 0
(gdb) print events[i].value
$4 = -1
(gdb) continue
Continuing.

Breakpoint 1, EV_HandleEvents (joystick=0xd20450) at src/joystick/linux/SDL_sysjoystick.c:921
921             };
(gdb) print stick
No symbol "stick" in current context.
(gdb) print joystick
$5 = (SDL_Joystick *) 0xd20450
(gdb) continue
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0x00007fcc5ff892dc in EV_HandleEvents (joystick=0xd20450) at src/joystick/linux/SDL_sysjoystick.c:945
945                             hats = SDL_joylist[stick->index].map->hatmap+hat;
(gdb) print stick
No symbol "stick" in current context.
(gdb) bt
#0  0x00007fcc5ff892dc in EV_HandleEvents (joystick=0xd20450) at src/joystick/linux/SDL_sysjoystick.c:945
#1  0x00007fcc5ff8a2c7 in SDL_SYS_JoystickUpdate (joystick=0x0) at src/joystick/linux/SDL_sysjoystick.c:1141
#2  0x00007fcc5ff5709d in SDL_JoystickUpdate () at src/joystick/SDL_joystick.c:540
#3  0x00007fcc5ff2d069 in SDL_PollEvent (event=0x0) at src/events/SDL_events.c:393
#4  0x0000000000401187 in process_events ()
#5  0x0000000000401409 in main ()
[...]
I used gdb a long time ago and I'm not sure to have used it correctly in this case

> Is there any chance I could borrow the joystick for a few days to test with? 
> Or can I remote log into your system for debugging?

if you live near paris, France I can bring you the joy and USB adaptor.
I prefer not to open this system from the net.
Comment 6 Sam Lantinga 2009-09-27 23:39:37 UTC
In the last test it looks like the source code doesn't correspond to your binary.

Can you re-build SDL with -O2 removed from the Makefile CFLAGS, and re-run your test?  You should also be able to get the same result from testjoystick, included in the SDL test directory.

There's special code to handle those joysticks in SDL, unfortunately I don't have the hardware to test them myself.

If you get the same crash, can you then edit src/joystick/linux/SDL_sysjoystick.c and add the following line to the top:
#define NO_LOGICAL_JOYSTICKS

and rebuild and see what happens?

Thanks!
Comment 7 Sam Lantinga 2009-09-27 23:58:10 UTC
*** Bug 786 has been marked as a duplicate of this bug. ***
Comment 8 Shad 2009-09-28 13:11:45 UTC
I rebuild SDL with -O0 CLAGS, compiled the testjoystick and run it with gdb, here is what I got:

db ./testjoystick                                                                                                                                         
GNU gdb 6.8-7mdv2010.0 (Mandriva Linux release 2010.0)                                                                                                                         
Copyright (C) 2008 Free Software Foundation, Inc.                                                                                                                              
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-mandriva-linux-gnu"...
(gdb) run /dev/input/js0
Starting program: /home/shad/rpm/BUILD/SDL-1.2.13/test/testjoystick /dev/input/js0
[Thread debugging using libthread_db enabled]
[New Thread 0x7f057d5956f0 (LWP 31464)]
There are 2 joysticks attached
Joystick 0: WiseGroup.,Ltd MP-8866 Dual USB Joypad
       axes: 4
      balls: 0
       hats: 1
    buttons: 12
Joystick 1: WiseGroup.,Ltd MP-8866 Dual USB Joypad
       axes: 4
      balls: 0
       hats: 1
    buttons: 12
Watching joystick 0: (WiseGroup.,Ltd MP-8866 Dual USB Joypad)
Joystick has 4 axes, 1 hats, 0 balls, and 12 buttons

Program received signal SIGSEGV, Segmentation fault.
0x00007f057d17ac4b in FindLogicalJoystick (joystick=0x1b999a0, v=0x0) at src/joystick/linux/SDL_sysjoystick.c:850
850                if (SDL_joylist[i].logicalno == v->njoy) {
(gdb) bt
#0  0x00007f057d17ac4b in FindLogicalJoystick (joystick=0x1b999a0, v=0x0) at src/joystick/linux/SDL_sysjoystick.c:850
#1  0x00007f057d17afbe in HandleHat (stick=0x1b999a0, hat=0 '\0', axis=0, value=0) at src/joystick/linux/SDL_sysjoystick.c:946
#2  0x00007f057d17b741 in EV_HandleEvents (joystick=0x1b999a0) at src/joystick/linux/SDL_sysjoystick.c:1099
#3  0x00007f057d17b937 in SDL_SYS_JoystickUpdate (joystick=0x1b999a0) at src/joystick/linux/SDL_sysjoystick.c:1141
#4  0x00007f057d13ec0f in SDL_JoystickUpdate () at src/joystick/SDL_joystick.c:540
#5  0x00007f057d105b3c in SDL_PumpEvents () at src/events/SDL_events.c:383
#6  0x00007f057d105b4f in SDL_PollEvent (event=0x7fff5cabf110) at src/events/SDL_events.c:393
#7  0x000000000040101b in WatchJoystick ()
#8  0x0000000000401472 in main ()
(gdb) print SDL_joylist[i].logicalno
$1 = 0
(gdb) print v->njoy
Cannot access memory at address 0x0
(gdb) print v
$2 = (struct joystick_logical_mapping *) 0x0
(gdb) print i
$3 = 0


I tried the adding #define NO_LOGICAL_JOYSTICKS and that did't crashed.
[shad@azrael test]$ ./testjoystick  /dev/input/js0
There are 2 joysticks attached
Joystick 0: WiseGroup.,Ltd MP-8866 Dual USB Joypad
       axes: 4
      balls: 0
       hats: 1
    buttons: 12
Joystick 1: WiseGroup.,Ltd MP-8866 Dual USB Joypad
       axes: 4
      balls: 0
       hats: 1
    buttons: 12
Watching joystick 0: (WiseGroup.,Ltd MP-8866 Dual USB Joypad)
Joystick has 4 axes, 1 hats, 0 balls, and 12 buttons
####
# MOVING THE DIGITAL PAD
####
Joystick 0 hat 0 value: left
Joystick 0 hat 0 value: centered
Joystick 0 hat 0 value: up
Joystick 0 hat 0 value: centered
Joystick 0 hat 0 value: right
Joystick 0 hat 0 value: right down
Joystick 0 hat 0 value: down
Joystick 0 hat 0 value: centeredJoystick 0 axis 0 value: -1014
####
# MOVING LEFT ANALOG PAD
####
Joystick 0 axis 0 value: -4054
Joystick 0 axis 0 value: -6419
Joystick 0 axis 1 value: -9121
Joystick 0 axis 0 value: 0
####
# SWITCHING TO DIGITAL MODE AND MOVING THE DIGITAL PAD
####
Joystick 0 axis 0 value: -32768
Joystick 0 axis 0 value: 0
Joystick 0 axis 1 value: -32768
Joystick 0 axis 1 value: 0
Joystick 0 axis 0 value: 32767
Joystick 0 axis 0 value: 0
Joystick 0 axis 1 value: 32767
Comment 9 twilightinzero 2009-09-28 15:31:16 UTC
Compiling with #define NO_LOGICAL_JOYSTICKS also fixes my segfaults.

Finally! Thank you very much! :)
Comment 10 Sam Lantinga 2009-09-28 17:39:54 UTC
It looks like newer kernels do the logical device mapping in the driver, so it's no longer necessary (and crashes) in SDL.

I'm curious on what kernels the logical mapping code is necessary, and why it's currently crashing, so if anyone has one of these joysticks I can borrow or let me log in to remote debug, please let me know!