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

Author Topic: How to free sf::Texture during runtime  (Read 4527 times)

0 Members and 1 Guest are viewing this topic.

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
How to free sf::Texture during runtime
« on: October 29, 2012, 03:51:45 pm »
Hello.
I am making a game, and at main menu i have allot of images, and i am wondering how to "free / empty" them to improve performance during game, i will reload them once menu is up.

I thought about reloading 1x1 image, that would work.
But id really prefer to empty it somehow.
What are ways to do this?
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11047
    • View Profile
    • development blog
    • Email
Re: How to free sf::Texture during runtime
« Reply #1 on: October 29, 2012, 04:01:42 pm »
Sorry we have no idea what you're referring to. You either need to describe very detailed what you're doing, or waay better post a minimal example...

If you have different states (like menu, game, credits, etc) then it's best to use some kind of a state manager. There each state could be represented as class, then you can load stuff in the constructor and if the class gets removed the resource will be freed. As an example you could take a look at my SmallGameEngine. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How to free sf::Texture during runtime
« Reply #2 on: October 29, 2012, 04:03:03 pm »
Why would you keep an empty sf::Texture instance? Just destroy it, and create a new one when you need to reload the texture.

Or, if you don't want to use dynamic allocation:
texture = sf::Texture();

And are you sure that you really need to do that? Unless your video memory is full, it won't make any difference.
Laurent Gomila - SFML developer

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: How to free sf::Texture during runtime
« Reply #3 on: October 29, 2012, 07:06:32 pm »
That's what i am doing at the moment,

What i was asking, is there a function to clear it and keep the object.
"I don't know how to make a code box"
int main
{
sf::Texture a;
a.loadFromFile("somefile.png");
//Something happens
//Unload the image somehow
//Something happens
//Load the image again
}

I am currently loading it intro std::vector and freeing it when i don't need it.

The challenge is to make it as least memory requiring as possible.
« Last Edit: October 29, 2012, 07:08:44 pm by BaneTrapper »
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

 

anything