summaryrefslogtreecommitdiff
path: root/src/resources/ambientlayer.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-02-08 22:09:07 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-02-09 23:47:51 +0100
commit32996cee607c52ecef9be4638df554dd89b39c24 (patch)
treeb3c9987ea39b52e46e5969f938c3aa9002a4bd4c /src/resources/ambientlayer.cpp
parent8aeb42b16430c85e4bc4052d881b8335d4a2ff36 (diff)
downloadmana-client-32996cee607c52ecef9be4638df554dd89b39c24.tar.gz
mana-client-32996cee607c52ecef9be4638df554dd89b39c24.tar.bz2
mana-client-32996cee607c52ecef9be4638df554dd89b39c24.tar.xz
mana-client-32996cee607c52ecef9be4638df554dd89b39c24.zip
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
Diffstat (limited to 'src/resources/ambientlayer.cpp')
-rw-r--r--src/resources/ambientlayer.cpp10
1 files changed, 2 insertions, 8 deletions
diff --git a/src/resources/ambientlayer.cpp b/src/resources/ambientlayer.cpp
index d1fc93d3..c31afbac 100644
--- a/src/resources/ambientlayer.cpp
+++ b/src/resources/ambientlayer.cpp
@@ -32,6 +32,7 @@ AmbientLayer::AmbientLayer(Image *img, float parallax,
mSpeedX(speedX), mSpeedY(speedY),
mKeepRatio(keepRatio)
{
+ mImage->incRef();
if (keepRatio && !mImage->useOpenGL()
&& defaultScreenWidth != 0
@@ -47,17 +48,10 @@ AmbientLayer::AmbientLayer(Image *img, float parallax,
if (rescaledOverlay)
{
- // Replace the resource with the new one...
- std::string idPath = mImage->getIdPath() + "_rescaled";
- ResourceManager::getInstance()->addResource(idPath, rescaledOverlay);
+ mImage->decRef();
mImage = rescaledOverlay;
- rescaledOverlay->incRef();
}
- else
- mImage->incRef();
}
- else
- mImage->incRef();
}
AmbientLayer::~AmbientLayer()