PDA

View Full Version : SDL_TTF - Memory leak when drawing text



T-Bear
02-01-2014, 08:41 PM
Hey guys.

I am currently playing around with SDL and am having a memory leak when rendering some text. I have found out that the code causing the memory leak is the one below. The code is simplified.



For I:= 0 To High(FElements) Do
begin
Color.r:= 255; Color.g:= 0; Color.b:= 0; // Color is of type TSDL_COLOR.
Tmp:= TTF_RenderText_Blended(FElements[I].Font, 'Some text', Color); // Tmp is a pSDL_SURFACE.
SDL_BLITSURFACE(Tmp, NIL, Screen, Rect); // Rect is a pSDL_RECT.
end;


The problem is that although I know the leak is there (I suspect it is the pSDL_SURFACE), I don't know how to fix it. Any help would be appreciated.

Thanks!

Super Vegeta
02-01-2014, 10:48 PM
Quite simply, you need to either store the surface somewhere and reuse it, or call SDL_FreeSurface() as soon as you're done with blitting.

T-Bear
02-01-2014, 11:33 PM
Thanks for the help!