Segfault in SDL_SYS_CreateThread

I’m having strange segmentation fault problem here, with my new
game (still in development). The strange thing is, that my other game
Formido works great, and my new game which initializes SDL
in same way Formido does, crashes. Both are linked with
the same SDL, SDL_image and SDL_mixer libs. The initialization
is nothing special, just SDL_Init with video, audio + timer.

I tried to debug it in GDB, but I cannot do anything about it.
Backtrace shows something about function (?) named config ()
(I don’t have such thing, I have a simple config struct instance
called config, though) but when I run the program step-by-step,
it crashes somewhere in SDL_SYS_CreateThread.
Here’s some output from GDB:

—cut—
GNU gdb 5.3-22mdk (Mandrake Linux)
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type “show copying” to see the conditions.
There is absolutely no warranty for GDB. Type “show warranty” for details.
This GDB was configured as “i586-mandrake-linux-gnu”…
(gdb) run
Starting program: /home/mh/omat/Puzzle_game/puzzle
[New Thread 16384 (LWP 11335)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 16384 (LWP 11335)]
0x080535b3 in config ()
Current language: auto; currently c
(gdb)
(gdb) backtrace
#0 0x080535b3 in config ()
#1 0xd040099d in ?? ()
#2 0x4009a2c1 in pthread_create@@GLIBC_2.1 () from /lib/libpthread.so.0
#3 0x4009a38d in pthread_create at GLIBC_2.0 () from /lib/libpthread.so.0
#4 0x40065c62 in SDL_SYS_CreateThread (thread=0x80714d0, args=0x80713c0)
at SDL_systhread.c:99
#5 0x40065aa9 in SDL_CreateThread (fn=0x80738a0, data=0x80738a0)
at SDL_thread.c:257
#6 0x40066cdb in SDL_SYS_TimerInit () at SDL_systimer.c:282
#7 0x4006664c in SDL_TimerInit () at SDL_timer.c:90
#8 0x4001f125 in SDL_InitSubSystem (flags=49) at SDL.c:106
#9 0x4001f1f2 in SDL_Init (flags=49) at SDL.c:163
#10 0x0804d390 in init_sdl() () at src/init.cpp:63
#11 0x0804cba5 in main (argc=1, argv=0xbffff744) at src/main.cpp:28
#12 0x4022c80c in __libc_start_main () from /lib/libc.so.6
(gdb)

*** In next cut, I have set the break point to SDL_SYS_CreateThread
and I’m going step-by-step, when it crashes ***

Starting program: /home/mh/omat/Puzzle_game/puzzle
[New Thread 16384 (LWP 11363)]
[Switching to Thread 16384 (LWP 11363)]

Breakpoint 1, SDL_SYS_CreateThread (thread=0x80714d0, args=0x80713c0)
at SDL_systhread.c:92
92 if ( pthread_attr_init(&type) != 0 ) {
(gdb) step
88 {
(gdb)
92 if ( pthread_attr_init(&type) != 0 ) {
(gdb)
96 pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE);
(gdb)
99 if ( pthread_create(&thread->handle, &type, RunThread, args)
!= 0 ) {
(gdb)

Program received signal SIGSEGV, Segmentation fault.
0x080535b3 in config ()
(gdb)

—cut—

Any suggestions how to fix this nasty problem? I’m developing the game
in Windows with Dev-C++ (+MinGW) and I just checked if it ran correctly
on my Mandrake 9.1 (which it didn’t, as you can see :frowning:

Thanks for any help, because I would like to get this game working on
Linux as well, when it’s ready of course.–
Mika Halttunen
@Mika_Halttunen

Mika Halttunen wrote:

I’m having strange segmentation fault problem here, with my new
game (still in development). The strange thing is, that my other game
Formido works great, and my new game which initializes SDL
in same way Formido does, crashes. Both are linked with
the same SDL, SDL_image and SDL_mixer libs. The initialization
is nothing special, just SDL_Init with video, audio + timer.

It seems to crash in the creation of the timer thread, if you use only
SDL_GetTicks() you don’t need SDL_INIT_TIMER, you need it only if you
are using async timers. So maybe you could remove it from the SDL
initialization.

Be also sure to compile your programs with the correct flags (the ones
you get from “sdl-config --cflags --libs”).

If you don’t use sdl-config, but you compile it at hand remember that
you need to add “-D_REENTRANT” in your cflags and link with -lpthread.

Bye,
Gabry

It seems to crash in the creation of the timer thread, if you use only
SDL_GetTicks() you don’t need SDL_INIT_TIMER, you need it only if you are
using async timers. So maybe you could remove it from the SDL
initialization.

I need to use timers, and, as I said, it works on Formido. Weird.

Be also sure to compile your programs with the correct flags (the ones
you get from “sdl-config --cflags --libs”).

I’m doing that too…–
Mika Halttunen
@Mika_Halttunen