gdb segfault in main_arena

I'm trying to debug a game. The game is compiled with debug symbols, and when I run it in gdb and make it crash, I get the following message:


Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6f5a6b8 in main_arena () from /usr/lib/libc.so.6


When I run it in valgrind it doesnt segfault at all. Anyone know how to read a message like this? I've tried to read up on it, but in all of the examples i've come across the file and the line of code responsible has shown up as well.


Fafner
What a segmentation fault means is that your program is trying to access memory on the heap that it doesn't have access to. There are a few reasons this could happen, which include:

1. Uninitialized pointers.
2. Running off the end of an array.
3. Trying to access memory after freeing it.
4. Trying to dereference a null pointer.

What exactly does valgrind output for your program? Even if it doesn't spot the memory muck-up (which it should), I'd still search through the code of main_arena for a spot where one of the situations I listed above happen.

EDIT: +1 Zhuge

-Albatross
Last edited on
Also, I'd run a stack trace in gdb after the crash to pinpoint where it is dying, which is often helpful in figuring out the source of the problem.
Thanks both of you, I ran a stacktrace and it pinpointed where it was dying, so I have something to work from:) Also, what could main_arena be? I've never seen it before, and its nowhere in my code... Maybe its in one of the libraries (sfml and box2d)?

EDIT: OK, the culprit seems to be the following line

1
2
3
4
5
virtual void induceUpdate(int _x, int _y) {
	for(Object *o : children) {
		if (!o->lost) o->induceUpdate(_x, _y); //THIS IS THE ONE
	}
}


so I guess its reasonable to assume that at least one of these pointers is going nowhere. This is a function in the Object-class, which is the top-level abstract class representing an object in my game. The way I remove objects is to mark them as lost, and then in each run of the game-loop run the following code:

1
2
3
4
5
6
7
8
9
10
11
void Object::removeLost(void) {
	for(std::vector<Object *>::iterator it = children.begin(); it != children.end();) {
		if ((*it)->lost) {
			delete *it;
			it = children.erase(it);
		} else {
			(*it)->removeLost();
			it++;
		}
	}
}


I've been a bit worried about it, does it look safe? :P

Thanks again :)
Last edited on
Topic archived. No new replies allowed.