I’ve run into my fair share of seg faults while blitting and gotten around them, but this has got me hitting my head against the wall. i’ll I am trying to do is swap one surface with new one. The order I am calling it is changeSurface(); then drawRect(); Any help would greatly be appreciated.
class surfaceID
{
public:
surfaceID(){s=NULL;name="";}
…
SDL_Surface *s;
…
};
std::vector surfaces;
int gfxengine_sdl::changeSurface(int &id,SDL_Surface *newsurf)
{
if(newsurf==NULL)return -1;
if(id==-1)
{
…
}
if(surfaces[id].s!=NULL)
{
-
SDL_FreeSurface(surface[id].s);
-
}//SDL_FreeSurface(surface[id].s); ///This by passes the seg fault, but then I have memory leakage :(
surfaces[id].s=newsurf;
return 1;
}
int gfxengine_sdl::drawRect(int id)
{
if(id==-1)return -1;
if(surfaces[id].s==NULL) return -1;
SDL_BlitSurface(surfaces[id].s,NULL,screen,&surfaces[id].coords); //seg faults here!!!
return 1;
}