There’s not enough information here to really answer your question. But
a few things that might be happening are this.
Are you creating Image instances that aren’t being used?
Image img[3];
img[0].load(“this.png”);
img[1].load(“that.png”);
// stuff
Segfault.
If so, it’s your free call on the uninitalized 3rd member of the array.
This would also apply to things that failed to load, like bad files etc.
A good solution to this is to set your mp_s_img = 0 in the constructor,
and have your destructor look something like:
if (mp_s_img) SDL_FreeSurface(mp_s_img);
The other common problem you might be having is you’re either
initalizeing an Image class with the result of SDL_SetVideo, or you’ve
derived a Video class from Image. In either case, the deconstructor is
probably trying to free the screen surface, which you’re not supposed to
do. If that’s the case, introduce a concept of ownership into your
Image class. An internal bool that’s always true in Image, but you can
set to false in a derived class, and will be checked before freeing the
surface in the destructor.On Fri, 2004-05-21 at 16:58, NighTiger wrote:
Hi,
I’ve an Image class. My destructor is
Image::~Image
{
SDL_FreeSurface(mp_s_img);
}
in my main.cc I’ve
while(!game.Keyboard())
{
when Keyboard return 1 than my program close, and the destructor for all
my objects is call.
But if I use the destructor in this mode, the program return to me
Fatal signal: Segmentation Fault (SDL Parachute Deployed)
why?
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl