Jump to content
  • Advertisement
Sign in to follow this  
pandaraf

Need Help : SDL_FreeSurface doesn't work?

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

If you intended to correct an error in the post then please contact us.

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? mellow.png

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
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! wink.png

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!