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

Author Topic: Unload Image  (Read 5289 times)

0 Members and 1 Guest are viewing this topic.

e_barroga

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Unload Image
« 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()

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Unload Image
« Reply #1 on: July 10, 2010, 03:17:17 pm »
Quote
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.

Quote
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.
Laurent Gomila - SFML developer

e_barroga

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Unload Image
« Reply #2 on: July 11, 2010, 03:36:19 am »
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?

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Unload Image
« Reply #3 on: July 11, 2010, 10:33:16 am »
Quote from: "e_barroga"
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.
SFML / OS X developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Unload Image
« Reply #4 on: July 11, 2010, 11:44:35 am »
You can do this
Code: [Select]
image = sf::Image();

But the question is: why do you want to unload the image but keep the corresponding instance?

Quote
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.
Laurent Gomila - SFML developer

e_barroga

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Unload Image
« Reply #5 on: July 12, 2010, 01:31:13 am »
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).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Unload Image
« Reply #6 on: July 12, 2010, 08:19:01 am »
Quote
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?
Laurent Gomila - SFML developer

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Unload Image
« Reply #7 on: July 12, 2010, 10:17:04 am »
I used something like
Code: [Select]
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.
Mindiell
----

 

anything