I am finally getting around to debugging my game, and it will be the first c++ program I have debugged, and the first time I've dealt with segmentation faults.
I updated my project to Eihort and worked around some problems I had the last time I tried to do it, but now segmentation faults are popping up in what I thought was very mundane and safe code.
I guess what I'm asking is what generally causes code to segfault. I can backtrace and comment out the offending lines, but they occur in a few critical places.
[Solved]SegFault questions.
-
- Goblin
- Posts: 279
- Joined: Sun Feb 19, 2006 1:08 am
[Solved]SegFault questions.
Last edited by big_o on Thu May 31, 2007 3:43 am, edited 1 time in total.
- Kujara
- Halfling
- Posts: 73
- Joined: Wed Nov 15, 2006 4:18 pm
- Location: Paris, France
Segfault are caused by bad access to memory, in almost all cases :
Trying to delete a pointer 2 times in a row.
Trying to use a pointer that doesn't point on anything, or points to something wrong.
Bad casts then access to a function/member variable that doesn't, in fact, exist.
Losing track of a pointer, then the garbage collector will try to delete it at the end of the program, possibly causing an error if the destructor relied on something else existing.
Exceeding the bounds of an array, which leads to you using something you're not supposed to touch.
Trying to delete a pointer 2 times in a row.
Trying to use a pointer that doesn't point on anything, or points to something wrong.
Bad casts then access to a function/member variable that doesn't, in fact, exist.
Losing track of a pointer, then the garbage collector will try to delete it at the end of the program, possibly causing an error if the destructor relied on something else existing.
Exceeding the bounds of an array, which leads to you using something you're not supposed to touch.
- Emmeran
- Goblin
- Posts: 272
- Joined: Wed Jun 02, 2004 11:47 am
- Location: Erlangen
- Contact:
the most common cause is a corruption of the heap.
for detailed informations with examples you can look here too:
http://www.ogre3d.org/wiki/index.php/Heap_Corruption
for detailed informations with examples you can look here too:
http://www.ogre3d.org/wiki/index.php/Heap_Corruption
- SpaceDude
- Bronze Sponsor
- Posts: 822
- Joined: Thu Feb 02, 2006 1:49 pm
- Location: Nottingham, UK
- x 3
- Contact:
-
- Goblin
- Posts: 279
- Joined: Sun Feb 19, 2006 1:08 am
I got it working. It was a quirk in the game state code from the wiki.
In the exit method for the states I do a lot of cleanup code, and the whenever states are changed the framestarted method for the previous state is called one last time, after its exit method has already been called.
At least that is what it looks like its doing, and the only thing that can explain my problem.
When the return to main menu button is clicked in my game the game is paused, but when the exit method is called it is unpaused, and then the program attempts to update the player one last time, which is impossible since the player no longer exists.
Thanks for the help.
In the exit method for the states I do a lot of cleanup code, and the whenever states are changed the framestarted method for the previous state is called one last time, after its exit method has already been called.
At least that is what it looks like its doing, and the only thing that can explain my problem.
When the return to main menu button is clicked in my game the game is paused, but when the exit method is called it is unpaused, and then the program attempts to update the player one last time, which is impossible since the player no longer exists.
Thanks for the help.