Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Iggy

Pages: [1]
1
Graphics / Drawing to a sf::RenderTexture causing memory leak.
« on: May 23, 2015, 12:14:50 am »
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.

2
General / Help drawing only onscreen sprites
« on: April 21, 2015, 07:52:25 pm »
Hi there, im having some trouble streaming sprites that are within screen space. For example if i have 5000 sprites in my level but only 500 are within the screen, i only want to draw those 500 and not blindly draw the full 5000.

Here's some code, note that the windows view is always centered on pEngine->get_player().
for (auto& ColumnTile : Row)
{
    //Trying to check if tile is within the screen? or am i wrong
        if (ColumnTile.graphics_shape().getPosition().x > pEngine->get_player()->getPosition().x - (RenderTarget.getSize().x / 2) &&
                ColumnTile.graphics_shape().getPosition().x < pEngine->get_player()->getPosition().x + (RenderTarget.getSize().x / 2) &&
                ColumnTile.graphics_shape().getPosition().y > pEngine->get_player()->getPosition().y - (RenderTarget.getSize().y / 2) &&
                ColumnTile.graphics_shape().getPosition().y < pEngine->get_player()->getPosition().y + (RenderTarget.getSize().y / 2)
                )
        {
                //draw if it's on the screen
                RenderTarget.draw(ColumnTile);
        }
}

The problem is half of the map dissapears (is not drawn), or to many sprites are drawn when they shouldn't be - it just doesn't work. Anyone have any idea why?

Help is much appreciated, thanks.

EDIT: Also the sprites are definatly initialized to the correct position, as they are all drawn perfect without the attempted bounds check.

Pages: [1]
anything