Sign in to follow this  
fireshadow4126

Segmentation Fault When Calling Draw Function

Recommended Posts

Hello,

I'm working on my game framework. It compiles fine, but when I run the executable (which is eventually going to be a working game), I get this message from gdb:

[CODE]
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b73152 in Survive::Game::TwoD::Entity2D::draw (this=0x91a, display=0x640f20) at libsurvive/src/game/2d/Entity2D.cpp:26
26 spr.draw(display, x, y);
[/CODE]

This is the definition of Entity2D::draw:

[CODE]
void Entity2D::draw(SDL_Surface *display) {
spr.draw(display, x, y);
}
[/CODE]

[i]display[/i] is a pointer to the screen, I know it is valid.
[i]spr[/i] is the entity's underlying sprite. I know it has been constructed correctly, because the entity initialized fine.
[i]x[/i] and [i]y[/i] are the coordinates to draw the sprite at. They have both been instantiated.

What might be causing this then?

I'm working in Ubuntu, using makefiles generated by premake to build.

Thanks in advance!

Share this post


Link to post
Share on other sites
This looks strange.
The this-pointer is an implicit parameter that you cannot see normaly. The this-pointer seems to be wrong. So you have no Entity2D object where you can call the draw method on.
This would think that something long before the crash goes wrong.

Share this post


Link to post
Share on other sites
[quote name='Tribad' timestamp='1340976247' post='4953948']
This looks strange.
The this-pointer is an implicit parameter that you cannot see normaly. The this-pointer seems to be wrong. So you have no Entity2D object where you can call the draw method on.
This would think that something long before the crash goes wrong.
[/quote]
I agree with this. 0x91a is an unusual value for a pointer and suggests that something earlier in your program is scribbling over memory that it shouldn't.

I'm not familiar with gdb (or the Linux toolchain in general) so I don't know it's capabilities for helping you find that "something", but Valgrind or similar - if gdb proves unhelpful here - should be able to. Edited by mhagain

Share this post


Link to post
Share on other sites
Never mind, I was able to solve it.

It turns out that my implementation of a linked list was messed up, so there were some bad pointers in there.

On to fixing the next problem!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this