So I have a fairly simple game. Most of the sprites used are created at startup and stored in shared pointers. According to the VS profiler, the memory usage is around 147MB. At this point there are several sprites and textures created and loaded, but only a few of them drawn. Upon a button press some extra sprites are now drawn. This causes the memory to go up to about 149-150 and it continues to grow by 1MB as new sprites get added (no new textures are loaded after the startup).
This is the constructor of the wrapper class for animating the sprites, which inherits from sf::Drawable (the overriden draw function just draws the sprite). The texture and the sprite are stored as shared pointers.
AnimatedSprite::AnimatedSprite(const std::shared_ptr<sf::Texture>& a_Texture, const float a_TotalTime, const int a_FrameCount):
m_Texture(a_Texture),
m_FrameTime(a_TotalTime),
m_CurrentFrame(0),
m_FrameCount(a_FrameCount)
{
m_Sprite = std::make_shared<sf::Sprite>(*m_Texture);
sf::Vector2i size = static_cast<sf::Vector2i>(m_Texture->getSize());
size.x /= m_FrameCount;
m_Sprite->setTextureRect(sf::IntRect(0, 0, size.x, size.y));
}
And this is the function that creates the sprite:
void Rendering::CreateSprite(const EBUBBLE_TYPE a_Type, const sf::Vector2f& a_Position, const float a_Rotation, std::shared_ptr<AnimatedSprite>& a_NewSprite)
{
a_NewSprite = std::make_shared<AnimatedSprite>(m_BubbleTextures.at(a_Type),BUBBLE_FRAME_TIME,4);
sf::Vector2f size = BubbleMath::ToVector2f(m_BubbleTextures.at(a_Type)->getSize());
size.x /= 4;
a_NewSprite->GetSprite()->setScale(bubble_sizes.at(a_Type) * PIXEL_TO_METER * 2 / size.x, bubble_sizes.at(a_Type) * PIXEL_TO_METER * 2 / size.y);
float x = bubble_sizes.at(a_Type) * PIXEL_TO_METER / a_NewSprite->GetSprite()->getScale().x;
float y = bubble_sizes.at(a_Type) * PIXEL_TO_METER / a_NewSprite->GetSprite()->getScale().y;
a_NewSprite->GetSprite()->setOrigin(x, y);
a_NewSprite->SetPosition(a_Position);
a_NewSprite->SetRotation(a_Rotation);
}
The sprites that need to be drawn are just looped through like this:
void Rendering::PlayDraw() const
{
for (const auto& element : m_Container)
{
m_Window->draw(*element);
}
m_Window->draw(*m_Line);
m_Window->draw(*m_PreviewBubbles.at(m_ActiveBubble));
for (auto& element : m_BubbleSprites)
{
m_Window->draw(*element);
}
m_Window->draw(*m_ScoreBackground);
m_Window->draw(*m_ScoreText);
}
Am I missing something here that could cause the extra memory usage or is it just the profiler detecting things wrong?