Jump to content
  • Advertisement
Sign in to follow this  
Robin04

SDL Memory Leak

This topic is 1416 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi!

 

I've been developing my Pong game in SDL for about a week or two. Now i checked if there is any memory leak in my program, and I realized that, there is. I figured out that the leak is in the Draw function of the ScoreBoard class that is used to handle the points of the players. I tried several solutions like double-checking that all my SDL_Surfaces are freed, but nothing helped. I paste the Draw function here for you, but if you can't find the problem I can put the whole class as well.

void ScoreBoard::Draw(SDL_Renderer* p_Renderer)
{
	m_Surface = TTF_RenderText_Solid(m_Font, std::to_string(m_Point[LEFT]).c_str(), m_Color);
	m_Texture = SDL_CreateTextureFromSurface(p_Renderer, m_Surface);
	SDL_FreeSurface(m_Surface);

	SDL_QueryTexture(m_Texture, 0, 0, &m_srcRect.w, &m_srcRect.h);
	m_destRect.w = m_srcRect.w;
	m_destRect.h = m_srcRect.h;
	m_destRect.x = WINDOW_WIDTH / 4;
	m_destRect.y = 50;
	SDL_RenderCopy(p_Renderer, m_Texture, &m_srcRect, &m_destRect);

	m_Surface = TTF_RenderText_Solid(m_Font, std::to_string(m_Point[RIGHT]).c_str(), m_Color);
	m_Texture = SDL_CreateTextureFromSurface(p_Renderer, m_Surface);
	SDL_FreeSurface(m_Surface);

	SDL_QueryTexture(m_Texture, 0, 0, &m_srcRect.w, &m_srcRect.h);
	m_destRect.w = m_srcRect.w;
	m_destRect.h = m_srcRect.h;
	m_destRect.x = WINDOW_WIDTH / 2 + WINDOW_WIDTH / 4;
	m_destRect.y = 50;
	SDL_RenderCopy(p_Renderer, m_Texture, &m_srcRect, &m_destRect);

	SDL_DestroyTexture(m_Texture);
}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!