• 13
• 14
• 27
• 9
• 9

Segmentation Fault When Calling Draw Function

This topic is 2086 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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:

 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); 

This is the definition of Entity2D::draw:

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

display is a pointer to the screen, I know it is valid.
spr is the entity's underlying sprite. I know it has been constructed correctly, because the entity initialized fine.
x and y 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.

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 on other sites
Where is Entity2D::draw called from?

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.

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 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!