SFML community forums

Help => Graphics => Topic started by: Deftwun on October 04, 2011, 04:46:42 am

Title: Release SF::image resource
Post by: Deftwun 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?
Title: Release SF::image resource
Post by: Deftwun on October 04, 2011, 04:48:29 am
PS : I think I may possibly be over engineering this :)
Title: Release SF::image resource
Post by: Disch 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);
Title: Release SF::image resource
Post by: Laurent 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".