[SDL] sdl freesurface causing seg faults when blitting.
CWC
charlesw at blackfoot.net
Mon Mar 3 22:05:14 PST 2008
> SDL_BlitSurface(surfaces[id].s,NULL,screen,&surfaces[id].coords); //seg faults here!!!
Of course a seg fault is caused by illegal access to memory, and this
line includes 4 pointers ... one of them is invalid.
NULL can be ruled out, so the trick would be to break out the other
three pointers onto separate lines.
You could try:
SDL_BlitSurface(surfaces[id].s,
NULL,
screen,
&surfaces[id].coords);
and possibly get the segfault to identify the one it doesn't like. If
your compiler optomizes away the distinction, you could try:
SDL_Rect tempRect;
= &surfaces[id].coords;
SDL_Surface *tempSurface = surfaces[id].s;
tempRect.x = tempRect.y = 0;
temprect.w = surfaces[id].coords.w // If it blows up here, there's
//something wrong with &surfaces[id].coords
tempRect.h = surfaces[id].coords.h;
if ((tempSurface->w != tempRect.w) ||
(tempSurface->h != tempRect.h))
{
cerr << "Gotcha, bad pointer : surfaces[id].s";
exit (-1);
}
SDL_BlitSurface(tempSurface,NULL,screen,&tempRect);
===========
It's not intended to be production quality code, just explicit access to
your pointers on separate lines to see which one is segfaulting.
If it still segfaults while blitting, check 'screen'.
More information about the SDL
mailing list