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

Author Topic: Release SF::image resource  (Read 1685 times)

0 Members and 1 Guest are viewing this topic.

Deftwun

  • Newbie
  • *
  • Posts: 27
    • View Profile
Release SF::image resource
« on: October 04, 2011, 04:46:42 am »
Is their a way to release an sf::image without deleting it. Also without modifying the sfml source..

I'm trying to put together a resource manager that can cache certain resources depending on the game state and quickly load and release them. but I have my image resource inherit from sf::image and dont really see a public function that would allow that.

the only thing I can think of would be to have a sf::image member in my resource class like so...

Code: [Select]

class myImageResource{
    private:
        sf::image * mySFImage;
        std::string myFileName;
    public:

        myImageResource(std::string theFileName):
            myFileName(theFileName)
            mySFImage(new sf::image)   //<--- not really sure if thats legal but you get the idea...

        void Load(){
             mySFImage->LoadFromFile(mFileName
        }
       
        void Release(){
            delete mySFImage;
        }

};


this is just an example but it already feels hacky and unsafe. I dont want to have to create and delete the sf::image every time ya know? I really want the resource to inherit from sf::image to make things streamlined.

any thoughts, comments?

Deftwun

  • Newbie
  • *
  • Posts: 27
    • View Profile
Release SF::image resource
« Reply #1 on: October 04, 2011, 04:48:29 am »
PS : I think I may possibly be over engineering this :)

Disch

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Release SF::image resource
« Reply #2 on: October 04, 2011, 06:35:55 am »
Code: [Select]
image.Create(0,0); might work.  If not, then
Code: [Select]
image.Create(1,1);

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Release SF::image resource
« Reply #3 on: October 04, 2011, 07:40:09 am »
Why would you want to keep an empty sf::Image instance? If you want to release the image, it seems more natural to completely get rid of the whole object.

Quote
Code: [Select]
image.Create(0,0);

I prefer this solution:
Code: [Select]
image = sf::Image();
But it's still a "hack".
Laurent Gomila - SFML developer

 

anything