SDL.Joystick objects cause a Segmentation Fault on program exit
Imported from http://bugzilla.roxen.com/bugzilla/show_bug.cgi?id=5832
Reported by pclar7@yahoo.co.uk
A program that creates an SDL.Joystick object reports a Segmentation Fault to the console on program exit. Otherwise, SDL.Joystick objects seem to function perfectly.
This short program will reproduce the error (you need a joystick plugged in):
int main()
{
SDL.init(SDL.INIT_VIDEO|SDL.INIT_JOYSTICK);
SDL.Surface screen = SDL.set_video_mode(640, 480, 0, SDL.SWSURFACE);
// How many joysticks?
int nj = SDL.num_joysticks();
for ( int i = 0; i < nj; ++i )
{
// Create the SDL.Joystick object.
SDL.Joystick my_joy = SDL.Joystick(i);
write("%d: %s\n", my_joy->index(), my_joy->name());
} // for
// Clean up.
SDL.quit();
return 0;
} // main
Here are the results of a gdb backtrace: Reading symbols from /usr/local/bin/pike...done. (gdb) set args try_joystick.pike (gdb) run Starting program: /usr/local/bin/pike try_joystick.pike [Thread debugging using libthread_db enabled] 0: Microsoft X-Box 360 pad
Program received signal SIGSEGV, Segmentation fault.
0x00475caf in SDL_JoystickClose () from /usr/lib/libSDL-1.2.so.0
(gdb) backtrace
#0 0x00475caf in SDL_JoystickClose () from /usr/lib/libSDL-1.2.so.0
#1 0x003d2f2f in exit_Joystick_struct (ev=1)
at /home/zino/hack-local/Pike/distmaker-7.8/src/post_modules/SDL/SDL.cmod:1848
#2 Joystick_event_handler (ev=1)
at /home/zino/hack-local/Pike/distmaker-7.8/src/post_modules/SDL/SDL.cmod:1991
#3 0x081264b3 in destruct_object (o=0x833ea2c, reason=DESTRUCT_NO_REFS)
at /home/matthew/Downloads/Pike-v7.8.352/src/object.c:863
#4 0x08128102 in low_destruct_objects_to_destruct ()
at /home/matthew/Downloads/Pike-v7.8.352/src/object.c:986
#5 0x0807e99e in low_return ()
at /home/matthew/Downloads/Pike-v7.8.352/src/interpret.c:2051
#6 0x0807ecac in jump_opcode_F_RETURN_0 ()
at /home/zino/hack-local/Pike/7.8-distmaker/src/interpret_functions.h:1614
#7 0x003c8e41 in ?? ()
#8 0x080771cc in catching_eval_instruction (pc=<value optimised out>)
at /home/matthew/Downloads/Pike-v7.8.352/src/interpret.c:2245
#9 0x0807d05d in jump_opcode_F_CATCH ()
at /home/zino/hack-local/Pike/7.8-distmaker/src/interpret_functions.h:1287
#10 0x003992f2 in ?? ()
#11 0x08080dcd in mega_apply (type=APPLY_LOW, args=1, arg1=0x833eb6c,
arg2=0x38) at /home/matthew/Downloads/Pike-v7.8.352/src/interpret.c:2213
---Type <return> to continue, or q <return> to quit---
#12 0x08081170 in apply (o=0x8393270, fun=0x821f691 "_main", args=1)
at /home/matthew/Downloads/Pike-v7.8.352/src/interpret.c:2604
#13 0x0806a468 in main (argc=2, argv=0xbffff444)
at /home/matthew/Downloads/Pike-v7.8.352/src/main.c:634
Problem can be fixed temporarily by explicitly destroying SDL.Joystick objects before call to SDL.quit (thanks to Henrik Grubbström at Roxen):
for ( int i = 0; i < nj; ++i )
{
// Create the SDL.Joystick object.
SDL.Joystick my_joy = SDL.Joystick(i);
write("%d: %s\n", my_joy->index(), my_joy->name());
destruct(my_joy);
} // for
I am using:
Pike v7.8 release 352
on:
Linux tyglyn 2.6.35-23-generic #41-Ubuntu SMP Wed Nov 24 10:18:49 UTC 2010 i686 GNU/Linux
(Ubuntu 10.10, i386)
Thanks.