Public Group

# Need Help : SDL_FreeSurface doesn't work?

This topic is 2377 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites
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?

##### Share on other sites

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!

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 12
• 10
• 13
• 104
• 11
• ### Forum Statistics

• Total Topics
632982
• Total Posts
3009689
• ### Who's Online (See full list)

There are no registered users currently online

×