Hi there, I'm using a render texture to draw a tilemap everything works perfect except for the fact there is a memory leak caused when i draw a sprite to it.
I left my game engine running overnight and when i checked in the morning i had "program stopped working" messagebox. So i started the engine again and watched the task manager. I found that memory just keeps building up without being released. I narrowed it down to a single line - drawing a sprite to a local render texture.
Here's the code:
//local variable too
sf::RenderTexture RenderTexture;
RenderTexture.create(RenderTarget.getSize().x + m_TileSize.first * 2, RenderTarget.getSize().y + m_TileSize.second * 2);
for (auto Tile : m_Tiles)//std::vector<sf::Sprite> m_Tiles;
{
if (ScreenSpace.intersects(Tile.getGlobalBounds()))//check if tile is onscreen
{
//get current world co-ordinates
SpriteWorldPos = Tile.getPosition();
//set sprites position to converted pixel co-ordinates
Tile.setPosition(sf::Vector2f{ RenderTarget.mapCoordsToPixel(Tile.getPosition()) });
//draw tile at pixel position
RenderTexture.draw(Tile);//this line causes memory to leak, no problem when this single line is commented
//^^^ problem line ^^^
//set position back at world co-ordinates
Tile.setPosition(SpriteWorldPos);
}
}
EDIT: I was originally using SFML 2.2 when i noticed this, i upgraded to 2.3 but same problem.