Hard ware surfaces

Hi Guys
I have some hardware surfaces, and if i understand correctly,
when i change from Full Screen to Windowed, i need to reload them,
which is what i am doing. but my memory is getting bigger and bigger
every time i change from full screen to windowed and vice versa.

I am freeing the surfaces before i create new surfaces as you can see.
So what am i doing wrong?

void ReloadHardwareLevel()
{
strcpy(PathName,“Gfx/”);
strcat(PathName,MapInfo[PlayingMap].MapName);
strcat(PathName,".jpg");
if(gLevel)
{
SDL_FreeSurface(gLevel);
}
gLevel = SDL_DisplayFormatAlpha(SDL_CreateRGBSurface(SDL_HWSURFACE,SCREEN_WIDTH,SCREEN_HEIGHT,32,RMASK,
GMASK, BMASK, AMASK));
SDL_Surface * TempSurface = SDL_DisplayFormatAlpha(IMG_Load(PathName));
CopySurface(TempSurface,gLevel); // my own function for copying the pixels
SDL_FreeSurface(TempSurface);
}

Thanks

Trish

Hi

On Behalf Of Patricia Curtis
I am freeing the surfaces before i create new surfaces as you can see.
So what am i doing wrong?

SDL_DisplayFormatAlpha does not free the surface you give it, so your
code leaks two surfaces at these lines, one from SDL_CreateRGBSurface
and one from IMG_Load:

gLevel =

SDL_DisplayFormatAlpha(SDL_CreateRGBSurface(SDL_HWSURFACE,SCREEN_WID

TH,SCREEN_HEIGHT,32,RMASK,
GMASK, BMASK, AMASK));
SDL_Surface * TempSurface =
SDL_DisplayFormatAlpha(IMG_Load(PathName));

Instead use something like

SDL_Surface* temp = SDL_CreateRGBSurface(…);
gLevel = SDL_DisplayFormatAlpha(temp);
SDL_FreeSurface(temp);

Make a similar change for the second case, and you shouldn’t lose any
more memory in that function.> -----Original Message-----


Jukka-Pekka Manninen

Patricia Curtis wrote:

gLevel = SDL_DisplayFormatAlpha(SDL_CreateRGBSurface(SDL_HWSURFACE,SCREEN_WIDTH,SCREEN_HEIGHT,32,RMASK,
GMASK, BMASK, AMASK));

You are leaking memory here, split the line and free the surface
allocated with SDL_CreateRGBSurface after SDL_DisplayFormatAlpha.

SDL_Surface * TempSurface = SDL_DisplayFormatAlpha(IMG_Load(PathName));

You are leaking memory here too, IMG_Load() returns a pointer to a
surface you have to free, the point is that SDL_DisplayFormat family
always return a NEW surface so you have to remove the original one :)–
Bye,
Gabry