user2781823
user2781823

Reputation: 52

Segmentation Fault Error at 0x00000000

So let me start with the error. I keep getting this seg fault when running GDB:

#0  0x00000000 in ?? ()
#1  0x0804aacc in find_closest_object (list=0x8052928, base=0xbffff148, 
dir=0xbffff130, last_hit=0x0, retdist=0xbffff0f0) at raytrace.c:34
#2  0x0804ab96 in ray_trace (model=0x80528f0, base=0xbffff148, dir=0xbffff130, 
pix=0xbffff160, total_dist=0, last_hit=0x0) at raytrace.c:80
#3  0x0804a99a in make_pixel (model=0x80528f0, x=0, y=0) at image.c:29
#4  0x0804aa09 in make_row (model=0x80528f0, y=0) at image.c:47
#5  0x0804aa53 in image_create (model=0x80528f0, out=0x8052788) at image.c:69
#6  0x08048aed in main (argc=3, argv=0xbffff2b4) at main.c:30

So basically, I keep getting this unknown error with 0x00000000 in ??. What on Earth does that mean? At line 34 on raytrace it says:

  dist = obj->hits(base, dir);

Any clue at all at what the problem could be? I could post more if necessary but not sure exactly what is needed. Thanks for the help!

EDIT: last_hit is supposed to be NULL so that isn't it.

Upvotes: 2

Views: 2938

Answers (2)

Srujan Barai
Srujan Barai

Reputation: 2365

You cannot access values that have undetermined values. Unless you run constructor, you object will have undetermined values will cannot be read but write to. So, you can change its value, but not read it.

It is possible it will give you access violation error.

Upvotes: 0

Alexis Wilke
Alexis Wilke

Reputation: 20798

You could be calling a virtual function which was not yet initialized. When C++ creates an object, it tends to clear the virtual table, then copy the parts of the table as required. If you call a function before all the constructors ran, then some of those pointers will be NULL and attempting to call them will do what you describe.

However, if obj->hits() is not a virtual function, then whatever it does destroys the stack and the return IP address is NULL at the time the RTS instruction (or equivalent) runs. At that point the processor tries to execute code at that NULL address. This is called buffer overrun when the buffer is created on the stack.

That's the two main reasons why you'd get such errors. Under MS-Windows, I've seen these also happen after you attempted to free the same memory buffer more than once. But that's not likely to end up being at NULL.

Upvotes: 2

Related Questions