i think you need to keep running it in gdb till it seg faults again.
or
turn on core dumps and when it does do it again, backtrace it.
also, i assume you are using gcc ? use -Wall, turn on all warnings. your
program should compile with out warnings. if you get warnings, that
might be a hint of where the problem could be.
matt
benang at cs.its.ac.id wrote:> Thanks. I’ve tried using gdb. But I can’t recreate the bug. Even when I
tried clicking at the same time as when the bug last occurs, it still
didn’t appear. I’m still confused right now.
Alberto Luaces said:
El Mi?rcoles, 21 de Febrero de 2007 14:34, benang at cs.its.ac.id escribi?:
What caused the SDL Parachute error?
To simplify this topic a little bit, I would say that a segmentation fault
means your that program tried to read or write a piece of memory not of
its
ownership. It is a very common mistake, mainly caused by incorrect
handling
of pointers. Or maybe you are also sending incorrect data to other
librarie’s
functions, and so on.
Why was it appear random ?
You are likely reading or writing a part of the memory through a wrong
array
index or pointer. Whenever the index or the pointer is correct, no error
is
generated.
You can run the program in the debugger and look at the backtrace when
your
program crashes to know what part of the code is buggy.
If something works in gdb, and not outside of gdb, I would suspect an
uninitialized variable. I’ve found sometimes things get initialized to
different values when running in gdb, and that makes them work.
If you really can’t find it, and can’t get it to happen in gdb, compile
with the SDL parachute disabled and set ulimit -c unlimited, and you’ll
get a core file. Then you can open that in gdb and find out what’s up.
Sorry for contributing to the increasing OT-ness of this thread.
El Mi?rcoles, 21 de Febrero de 2007 19:33, Gregory Smith escribi?:
Sorry for contributing to the increasing OT-ness of this thread.
Gregory, I think you are absolutely ON topic.
Just to ease things a bit, I have to mention that to disable the SDL parachute
in order to get a core dump when the program crashes, you have also to pass
the SDL_INIT_NOPARACHUTE flag to SDL_Init() at the beginning of your program.
In “debug mode” I think most numeric variables are automatically
initialized to zero. In “release mode” uninitialized numeric variables
are just given a chunk of memory and their values will be whatever
that chunk of memory happens to be when interpreting that kind of
numeric variable.
So watch out for places were you might assume that something was set to zero!
Just building on what Gregory said…
Hope that helps
/ TommyOn 22/02/07, Alberto Luaces wrote:
El Mi?rcoles, 21 de Febrero de 2007 19:33, Gregory Smith escribi?:
Sorry for contributing to the increasing OT-ness of this thread.
Gregory, I think you are absolutely ON topic.
Just to ease things a bit, I have to mention that to disable the SDL parachute
in order to get a core dump when the program crashes, you have also to pass
the SDL_INIT_NOPARACHUTE flag to SDL_Init() at the beginning of your program.
Thank you all. I’ve used the -Wall in the compiler (like what has been
suggested before) and it produces lots of warnings which seemed unrelated.
Mostly only the variable x will be initialized after y if defined like
this, not putting default in switch-case, comparing signed with unsigned,
etc. The funny thing is when I fixed most of the warnings, it worked (or
seemed to work because the bug didn’t show up for now).
@Alberto Luaces
I see. No wonder I couldn’t find the core dump. Thanks a lot. Will try that.
Tommy Hinks said:
In “debug mode” I think most numeric variables are automatically
initialized to zero. In “release mode” uninitialized numeric variables
are just given a chunk of memory and their values will be whatever
that chunk of memory happens to be when interpreting that kind of
numeric variable.
So watch out for places were you might assume that something was set to
zero!
Just building on what Gregory said…
Hope that helps
/ Tommy
El Mi?rcoles, 21 de Febrero de 2007 19:33, Gregory Smith escribi?:
Sorry for contributing to the increasing OT-ness of this thread.
Gregory, I think you are absolutely ON topic.
Just to ease things a bit, I have to mention that to disable the SDL
parachute
in order to get a core dump when the program crashes, you have also to
pass
the SDL_INIT_NOPARACHUTE flag to SDL_Init() at the beginning of your
program.