[SDL] sdl freesurface causing seg faults when blitting.

CWC charlesw at blackfoot.net
Mon Mar 3 20:52:15 PST 2008


Kevron Rees wrote:
> 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<surfaceID> 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 :(
>     }

Your diffs refer to 'surface[id].s' but your vector is named surface's'.

>     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;
> }
Are you certain '&surface[id].coords' is resolving as you desire?
???

> 
> 
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
> 



More information about the SDL mailing list