Skip to content
Snippets Groups Projects
Verified Commit d07f745e authored by Clayton Craft's avatar Clayton Craft
Browse files

tooltip: fix memory leaks / add destructor (MR 145)

parent 2e1f010f
No related branches found
No related tags found
No related merge requests found
......@@ -29,6 +29,14 @@ Tooltip::Tooltip(TooltipType type, int width, int height, int cornerRadius, Conf
{
}
Tooltip::~Tooltip()
{
if (texture) {
SDL_DestroyTexture(texture);
texture = nullptr;
}
}
int Tooltip::init(SDL_Renderer *renderer, const std::string &text)
{
SDL_Surface *surface;
......@@ -87,6 +95,11 @@ int Tooltip::init(SDL_Renderer *renderer, const std::string &text)
SDL_BlitSurface(textSurface, nullptr, surface, &textRect);
texture = SDL_CreateTextureFromSurface(renderer, surface);
TTF_CloseFont(font);
SDL_FreeSurface(textSurface);
SDL_FreeSurface(surface);
return 0;
}
......
......@@ -41,6 +41,7 @@ public:
@param config Config object
*/
Tooltip(TooltipType type, int width, int height, int cornerRadius, Config *config);
~Tooltip();
/**
Initialize tooltip
@param renderer Initialized SDL renderer object
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment