After rendering the text, you need to destroy the texture and surface - each TTF call creates a new surface!
Try moving ‘SDL_FreeSurface(surface)’ to be called after ‘SDL_RenderCopy(renderer, …)’ and before ‘SDL_DestroyTexture(texture)’, i.e:
Code:
SDL_RenderCopy(renderer, texture, NULL, &dstrect);
SDL_FreeSurface(surface);
SDL_DestroyTexture(texture);
Try moving ‘SDL_FreeSurface(surface)’ to be called after ‘SDL_RenderCopy(renderer, …)’ and before ‘SDL_DestroyTexture(texture)’, i.e:
Code:
SDL_RenderCopy(renderer, texture, NULL, &dstrect);
SDL_FreeSurface(surface);
SDL_DestroyTexture(texture);
Also, to optimize the code, you should insert the SDL_PollEvent-call into a while loop so it’s only called whenever a event is occuring, i.e:
Code:
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
{
quitMainLoop = true;
break;
}
case SDL_KEYDOWN:
{
quitMainLoop = true;
break;
}
}
}
// Rest of code (create surface, texture and such)
Ah yes - didn’t see them there [Laughing]
Is the output variable a std::string or something else ? If its the latter, perhaps you need to free that.
Glad it turned out alright. =)