Need Help : SDL_FreeSurface doesn't work?

Started by
1 comment, last by pandaraf 12 years ago
This is the code for the SDL_FreeSurface :

inside int main :

Uint32 start = 0;
bool running = true;
start = SDL_GetTicks();

and

while(QUIT==false){
if( running == true ) {
std::stringstream time;
time << "Timer: " << SDL_GetTicks() - start;
seconds = TTF_RenderText_Solid( font, time.str().c_str(), black );
apply_surface(( SCREEN_WIDTH - seconds->w ) / 2, 100, seconds, SCREEN );
//This line :
SDL_FreeSurface( seconds );
}


and this is what the screens say :

[sharedmedia=gallery:images:2080]

The text appear without erasing the previous surface.

Any suggest? mellow.png
Advertisement
Looks to me like the problem is that you are simply repainting the time without repainting the background first. Think of the surface as an actual canvas for a second. You have a picture on the there. Then you create a picture of the time. Next you paint that time picture onto your canvas surface. Before restarting the loop, you free the time picture (this doesn't affect the canvas image which still has the time already painted onto it). Then you get the new time, and paint the new time onto the surface (over the old time, but without removing the old time). If you want to erase the previous surface, what you really need to do is at the beginning of each loop re-apply the background (thus painting over the old time).

SDL_FreeSurface frees the image from memory, but it doesn't erase the image from other surfaces on which it has already been "painted".

Does that make sense?

Looks to me like the problem is that you are simply repainting the time without repainting the background first. Think of the surface as an actual canvas for a second. You have a picture on the there. Then you create a picture of the time. Next you paint that time picture onto your canvas surface. Before restarting the loop, you free the time picture (this doesn't affect the canvas image which still has the time already painted onto it). Then you get the new time, and paint the new time onto the surface (over the old time, but without removing the old time). If you want to erase the previous surface, what you really need to do is at the beginning of each loop re-apply the background (thus painting over the old time).

SDL_FreeSurface frees the image from memory, but it doesn't erase the image from other surfaces on which it has already been "painted".

Does that make sense?


Woah, that make sense. I should repaint the background before the surface appear? Thank You very much! wink.png

This topic is closed to new replies.

Advertisement