Hi everyone, I am new with SDL2
There are memory leak in my code, but I can’t understand
This is my code:
void Game::draw(std::string msg, int x, int y, SDL_Color color) {
SDL_Surface* surf = TTF_RenderText_Solid(font, msg.c_str(), color);
SDL_Texture* tex = SDL_CreateTextureFromSurface(renderer, surf);
SDL_Rect rect;
rect.x=x;
rect.y=y;
rect.w=surf->w;
rect.h=surf->h;
SDL_FreeSurface(surf);
SDL_RenderCopy(ren, tex, NULL, &rect);
SDL_DestroyTexture(tex);
}
In main loop I call function draw()
When I run my code, at first it uses 10M but after 1 second it uses 13M, then 17M… finnally it uses 27M and don’t change anymore.
I was free surface and destroy texture.
I try to remove line SDL_RenderCopy(ren, tex, NULL, &rect), everything is OK, don’t have memory leak anymore.
I thinks problem from line SDL_RenderCopy. But I don’t know why?
Tks.