0

I am trying to make a text box so i made this function to show text on screen,

i have a fps regulator, so the function is called 33 times a second.

I have an old computer (64 mb video ram and 1 ram + Pentium 4 CPU 2.8GHz)

when i remove this function from my code it never freeze, why?

MESSAGE (SDL_Surface *MESSAGE = NULL;) is declared at the top of my code under the include lines. ( So is SCREEN)

void text_box()
{
    MESSAGE = TTF_RenderText_Solid( font,  "Ligne #1" , noir ); 
    apply_surface( 2, 503, MESSAGE, SCREEN );   
    SDL_FreeSurface(MESSAGE);                 

    MESSAGE = TTF_RenderText_Solid( font,  "Ligne #2" , noir );
    apply_surface( 2, 510, MESSAGE, SCREEN );
    SDL_FreeSurface(MESSAGE);

    MESSAGE = TTF_RenderText_Solid( font,  "Ligne #3" , noir );
    apply_surface( 2, 517, MESSAGE, SCREEN );
    SDL_FreeSurface(MESSAGE);

    MESSAGE = TTF_RenderText_Solid( font,  "Ligne #4" , noir );
    apply_surface( 2, 524, MESSAGE, SCREEN );
    SDL_FreeSurface(MESSAGE);

    MESSAGE = TTF_RenderText_Solid( font,  "Ligne #5" , noir );
    apply_surface( 2, 531, MESSAGE, SCREEN );
    SDL_FreeSurface(MESSAGE);

    MESSAGE = TTF_RenderText_Solid( font,  "Ligne #6" , noir );
    apply_surface( 2, 538, MESSAGE, SCREEN );
    SDL_FreeSurface(MESSAGE);

    MESSAGE = TTF_RenderText_Solid( font,  "Ligne #7" , noir );
    apply_surface( 2, 545, MESSAGE, SCREEN );
    SDL_FreeSurface(MESSAGE);

    MESSAGE = TTF_RenderText_Solid( font,  "Ligne #8" , noir );
    apply_surface( 2, 552, MESSAGE, SCREEN );
    SDL_FreeSurface(MESSAGE);

    MESSAGE = TTF_RenderText_Solid( font,  "Ligne #9" , noir );
    apply_surface( 2, 559, MESSAGE, SCREEN );
    SDL_FreeSurface(MESSAGE);

    MESSAGE = TTF_RenderText_Solid( font,  "Ligne #10" , noir );
    apply_surface( 2, 566, MESSAGE, SCREEN );
    SDL_FreeSurface(MESSAGE);

    MESSAGE = TTF_RenderText_Solid( font,  "Ligne #11" , noir );
    apply_surface( 2, 574, MESSAGE, SCREEN );
    SDL_FreeSurface(MESSAGE);

    MESSAGE = TTF_RenderText_Solid( font,  "Ligne #12" , noir );
    apply_surface( 2, 581, MESSAGE, SCREEN );
    SDL_FreeSurface(MESSAGE);
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
  • Does your program run correctly for some time, and then fail? Or does it fail immediately? – Joe Z Dec 18 '13 at 03:40
  • When this function is included in my program it will sometime crash when i run the program. It do not crash everytime. When it is not included, everything is fine and run smoothly. So, immediatly but not every time. – user3105169 Dec 18 '13 at 03:41
  • I have a variable that is incremated every loop (Printed on screen and screen freeze with the number), it happen sometime that the loop ran 2 times and crashed. – user3105169 Dec 18 '13 at 03:45
  • Not sure what is happening, but the first thing I would do is add some debug tests to make sure `MESSAGE` is not null after calling `TTF_RenderText_Solid`. – Joe Z Dec 18 '13 at 03:47

0 Answers0