SFML community forums
Help => Graphics => Topic started by: e_barroga on July 10, 2010, 03:13:51 am
-
How do you unload an image from memory? Right now I am assuming the image is cleared from memory in the destructor of sf::Image.
Although I was wondering if there was a way to put your sf::Image object back to the state before the invocation of: sf::Image::Load()
-
How do you unload an image from memory? Right now I am assuming the image is cleared from memory in the destructor of sf::Image.
You're right. So, to clear an image, simply destroy the corresponding instance.
Although I was wondering if there was a way to put your sf::Image object back to the state before the invocation of: sf::Image::Load()
You can copy it to a temporary image, an assign it back later.
-
Why isn't there an Unload() method when there is a Load() method?
If it is cleared in the destructor, why not load the image in the constructor?
-
Why isn't there an Unload() method when there is a Load() method?
You'll have an image in an invalid state. That's not a good idea.
If you really want to remove from memory an unused image, use a resource manager : it will be easy to add/remove anything.
-
You can do this
image = sf::Image();
But the question is: why do you want to unload the image but keep the corresponding instance?
If it is cleared in the destructor, why not load the image in the constructor?
SFML doesn't use exceptions, therefore it never does anything that may fail in a constructor.
Moreover, images can't always be loaded at the moment they are constructed, so a default constructor + a Load function is always necessary.
-
Based on a flag, I wanted to preload an image or load it the first time it is used and unload it when it is not used (after the rendering step, the image was not drawn).
-
and unload it when it is not used
If it's not used, what difference does it make if it contains the previous pixels or nothing?
-
I used something like
image.Load("");
without checking the error (since there is an error). But it was just for a small sample one year ago. The state of the image was not important, all I wanted was to have a white rectangle onto the sprite.
But I don't know how the SFML handle this.