SDL_Init issue

All,
I have some code which uses SDL for both audio/timers and threads. The
program spawns several worker threads (using SDL threads) and the main
line code calls the SDL_Init() function once only.

When I run the program normally everything is fine BUT when I run it
thru a debugger (like gdb or NJAMD) I get a segment fault after the call
the SDL_Init().

gdb simply dies stone dead at this point with an invalid traceback
address which is useless so I ran NJAMD wrapper and it shits itself at
the same point however I get a little more info:

NJAMD/free: Address 0x0 not from malloc
called from ./transcoder_client[0x8058baf]
called from ./transcoder_client[0x804c4e6]

The first address above translates to the source code point where I call
SDL_Init(SDL_INIT_AUDIO|SDL_INIT_TIMER)

It is very likely that I have clobbered the stack earlier on as this is
new code and untested , or the debugger is getting confused with the
multiple threads ; I just wanted to check, before I dive in and hunt for
code problems, if there are an caveats concerning SDL_Init() and
multi-threaded models?
Are there any problems in calling SDL_init() more than once from
different threads in the same process context as I ‘may’ have this going
on too… :slight_smile:

Regards,
-Chris

Can’t really help if you’ve somehow clobbered the stack…You’ll have to
play around with the debugger and figure it out yourself.
However, there IS help in determining whether you’ve called SDL_Init() more
than once from different threads.
Have a look at SDL_WasInit.

http://docs.mandragor.org/files/Common_libs_documentation/SDL/SDL_Documentat
ion_project_en/sdlwasinit.html
<http://docs.mandragor.org/files/Common_libs_documentation/SDL/SDL_Documenta
tion_project_en/sdlwasinit.html>

It allows you to see which SDL subsystems have been initialised.

Good luck.

Cheers,
Kos_____

From: sdl-bounces@lists.libsdl.org [mailto:sdl-bounces at lists.libsdl.org] On
Behalf Of chris.2.dobbs at bt.com
Sent: 02 May 2007 18:13
To: sdl at lists.libsdl.org
Subject: [SDL] SDL_Init issue

All,
I have some code which uses SDL for both audio/timers and threads. The
program spawns several worker threads (using SDL threads) and the main line
code calls the SDL_Init() function once only.

When I run the program normally everything is fine BUT when I run it thru a
debugger (like gdb or NJAMD) I get a segment fault after the call the
SDL_Init().

gdb simply dies stone dead at this point with an invalid traceback address
which is useless so I ran NJAMD wrapper and it shits itself at the same
point however I get a little more info:

NJAMD/free: Address 0x0 not from malloc
called from ./transcoder_client[0x8058baf]
called from ./transcoder_client[0x804c4e6]

The first address above translates to the source code point where I call
SDL_Init(SDL_INIT_AUDIO|SDL_INIT_TIMER)

It is very likely that I have clobbered the stack earlier on as this is new
code and untested , or the debugger is getting confused with the multiple
threads ; I just wanted to check, before I dive in and hunt for code
problems, if there are an caveats concerning SDL_Init() and multi-threaded
models?

Are there any problems in calling SDL_init() more than once from different
threads in the same process context as I ‘may’ have this going on too…
:slight_smile:

Regards,
-Chris

NJAMD/free: Address 0x0 not from malloc
called from ./transcoder_client[0x8058baf]
called from ./transcoder_client[0x804c4e6]

free(NULL) is not an error. If I’m understanding what this is reporting,
that’s probably not the problem.

Try valgrind?

–ryan.

Valgrind has been my primary debugging tool for a few years now. It
can save countless debugging hours, and often points you right
at “sleeping” bugs you wouldn’t even find with a normal debugger.

Highly recommended!

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --'On Wednesday 02 May 2007 20:58, Ryan C. Gordon wrote:

NJAMD/free: Address 0x0 not from malloc
called from ./transcoder_client[0x8058baf]
called from ./transcoder_client[0x804c4e6]

free(NULL) is not an error. If I’m understanding what this is
reporting, that’s probably not the problem.

Try valgrind?

I had forgoton about that tool, tried it ages ago - thanks for the reminder as this seems to have located my problem:
%valgrind --tool=memcheck --leak-check=full --show-reachable=yes

Exellent tool, it even manages to trap thread specific signals.
Thanks,
-Chris> ----- Original Message -----

From: sdl-bounces@lists.libsdl.org on behalf of David Olofson
Sent: Wed 5/2/2007 10:18 PM
To: A list for developers using the SDL library. (includes SDL-announce)
Subject: Re: [SDL] SDL_Init issue

On Wednesday 02 May 2007 20:58, Ryan C. Gordon wrote:

NJAMD/free: Address 0x0 not from malloc
called from ./transcoder_client[0x8058baf]
called from ./transcoder_client[0x804c4e6]

free(NULL) is not an error. If I’m understanding what this is
reporting, that’s probably not the problem.

Try valgrind?

Valgrind has been my primary debugging tool for a few years now. It
can save countless debugging hours, and often points you right
at “sleeping” bugs you wouldn’t even find with a normal debugger.

Highly recommended!

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --’


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

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/ms-tnef
Size: 3489 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20070503/2bb8cc8b/attachment.bin

BTW the problem was simply a trace line with one too few %s (the extraneous string input was rather large too)…should have tried the usual disable trace before looking any further!

Thanks for comments to all
-Chris> ----- Original Message -----

From: sdl-bounces@lists.libsdl.org on behalf of @chris.2.dobbs_at_bt
Sent: Thu 5/3/2007 12:42 AM
To: sdl at lists.libsdl.org
Subject: RE: [SDL] SDL_Init issue

I had forgoton about that tool, tried it ages ago - thanks for the reminder as this seems to have located my problem:
%valgrind --tool=memcheck --leak-check=full --show-reachable=yes

Exellent tool, it even manages to trap thread specific signals.
Thanks,
-Chris

-----Original Message-----
From: sdl-bounces@lists.libsdl.org on behalf of David Olofson
Sent: Wed 5/2/2007 10:18 PM
To: A list for developers using the SDL library. (includes SDL-announce)
Subject: Re: [SDL] SDL_Init issue

On Wednesday 02 May 2007 20:58, Ryan C. Gordon wrote:

NJAMD/free: Address 0x0 not from malloc
called from ./transcoder_client[0x8058baf]
called from ./transcoder_client[0x804c4e6]

free(NULL) is not an error. If I’m understanding what this is
reporting, that’s probably not the problem.

Try valgrind?

Valgrind has been my primary debugging tool for a few years now. It
can save countless debugging hours, and often points you right
at “sleeping” bugs you wouldn’t even find with a normal debugger.

Highly recommended!

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --’


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

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/ms-tnef
Size: 3757 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20070503/908df4c6/attachment.bin

chris.2.dobbs at bt.com wrote:

BTW the problem was simply a trace line with one too few %s (the extraneous string input was rather large too)…should have tried the usual disable trace before looking any further!

If you use GCC with attribute you can make your trace calls return a
warning if an error of this type occurs, in your c/c++ header, here is
an example:

#if GNUC >= 3
void trace(const char *module, int level, const char *format, …)
attribute ((format(printf,3,4)));
#else
void trace(const char *module, int level, const char *format, …);
#endif
Bye,
Gabry

I didn’t know about that one, many thanks, will try it out.
-Chris> ----- Original Message -----

From: sdl-bounces@lists.libsdl.org [mailto:sdl-bounces at lists.libsdl.org]
On Behalf Of Gabriele Greco Sent: 03 May 2007 08:45 To: A list for developers using the SDL library. (includes SDL-announce) Subject: Re: [SDL] SDL_Init issue @chris.2.dobbs_at_bt wrote:

BTW the problem was simply a trace line with one too few %s (the
extraneous string input was rather large too)…should have tried the
usual disable trace before looking any further!

If you use GCC with attribute you can make your trace calls return a
warning if an error of this type occurs, in your c/c++ header, here is
an example:

#if GNUC >= 3
void trace(const char *module, int level, const char *format, …)
attribute ((format(printf,3,4))); #else
void trace(const char *module, int level, const char *format, …);
#endif


Bye,
Gabry


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

BTW , love the kobo game, my kids (and me) play it all the time…> ----- Original Message -----

From: sdl-bounces@lists.libsdl.org [mailto:sdl-bounces at lists.libsdl.org]
On Behalf Of David Olofson
Sent: 02 May 2007 22:18
To: A list for developers using the SDL library. (includes SDL-announce)
Subject: Re: [SDL] SDL_Init issue

On Wednesday 02 May 2007 20:58, Ryan C. Gordon wrote:

NJAMD/free: Address 0x0 not from malloc
called from ./transcoder_client[0x8058baf]
called from ./transcoder_client[0x804c4e6]

free(NULL) is not an error. If I’m understanding what this is
reporting, that’s probably not the problem.

Try valgrind?

Valgrind has been my primary debugging tool for a few years now. It can
save countless debugging hours, and often points you right at "sleeping"
bugs you wouldn’t even find with a normal debugger.

Highly recommended!

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --’


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