From 32996cee607c52ecef9be4638df554dd89b39c24 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Wed, 8 Feb 2012 22:09:07 +0100 Subject: Fixed wallpaper prescaling issues Image::SDLgetScaledImage was changed so that it tries to find an existing scaled version of the image first, and generates it when none exists. When it needs to generate one, this resource is added to the resource manager, partly to avoid duplicating the work later but mainly to keep memory management straightforward. This function also used to leak the scaled SDL_Surface since it wrongly assumed that Image::load would free it. To avoid filling up the memory with scaled wallpapers that are waiting 30 seconds until they will be deleted, the Resource::decRef function was extended with a parameter that allows telling it what to do with orphans. Calling decRef with Resource::DeleteImmediately will delete the resource immediately in case the resource is orphaned. Reviewed-by: Yohann Ferreira --- src/resources/resource.h | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/resources/resource.h') diff --git a/src/resources/resource.h b/src/resources/resource.h index 53b05ee8..af688eb0 100644 --- a/src/resources/resource.h +++ b/src/resources/resource.h @@ -33,21 +33,26 @@ class Resource friend class ResourceManager; public: - Resource(): mRefCount(0) {} + enum OrphanPolicy { + DeleteLater, + DeleteImmediately + }; + + Resource(): + mRefCount(0) + {} /** * Increments the internal reference count. */ - void incRef(); + void incRef() { ++mRefCount; } /** - * Decrements the reference count and deletes the object - * if no references are left. - * - * @return true if the object was deleted - * false otherwise. + * Decrements the reference count. When no references are left, either + * schedules the object for deletion or deletes it immediately, + * depending on the \a orphanPolicy. */ - void decRef(); + void decRef(OrphanPolicy orphanPolicy = DeleteLater); /** * Return the path identifying this resource. @@ -56,7 +61,7 @@ class Resource { return mIdPath; } protected: - virtual ~Resource(); + virtual ~Resource() {} private: std::string mIdPath; /**< Path identifying this resource. */ -- cgit v1.2.3-60-g2f50