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.


Messages - dorcsyful

Pages: [1]
1
General / Re: Memory usage increasing when drawing a sprite?
« on: October 23, 2024, 05:33:20 pm »
Okay so I sorted out my data types and the textures are now stored as unique pointers. However, the memory usage is still increasing depending on whether or not a sprite is drawn, both in debug and release mode.

2
General / Re: Memory usage increasing when drawing a sprite?
« on: October 21, 2024, 10:32:46 am »
So you you're saying I can just store all textures on the stack and AnimatedSprite can just store a reference to it? I thought they would be too big for the stack.

Thanks for reminding me about the sf::Sprite though, I needed it as a shared_ptr before I did some refactoring and forgot to change it.

3
General / Re: Memory usage increasing when drawing a sprite?
« on: October 17, 2024, 07:32:49 pm »
It's not really the amount of ram used is what I'm wondering about. I'm more concerned about the fact that the ram usage grows according to the draw calls by a lot. I thought that's only supposed to affect the CPU

4
General / Memory usage increasing when drawing a sprite?
« on: October 17, 2024, 03:34:08 pm »
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.

Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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?

Pages: [1]