Jump to content

  • Log In with Google      Sign In   
  • Create Account

Need Help : SDL_FreeSurface doesn't work?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 pandaraf   Members   -  Reputation: 108

Like
0Likes
Like

Posted 18 April 2012 - 08:54 PM

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 :

SDL FreeSurface error


The text appear without erasing the previous surface.

Any suggest? Posted Image

Sponsor:

#2 Zael   Members   -  Reputation: 154

Like
2Likes
Like

Posted 18 April 2012 - 09:53 PM

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?

#3 pandaraf   Members   -  Reputation: 108

Like
0Likes
Like

Posted 18 April 2012 - 10:29 PM

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! Posted Image




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS