summaryrefslogtreecommitdiff
path: root/src/resources/atlasmanager.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-10-03 17:04:56 +0300
committerAndrei Karas <akaras@inbox.ru>2012-10-03 17:51:24 +0300
commit4dc93e343e0fb4990320e1056bca666e8ce8c3d9 (patch)
treed2a9220f19605f450942a0a38a18512916a3e500 /src/resources/atlasmanager.cpp
parent42411c8963eec06448a5dbf565add0540d6987f1 (diff)
downloadplus-4dc93e343e0fb4990320e1056bca666e8ce8c3d9.tar.gz
plus-4dc93e343e0fb4990320e1056bca666e8ce8c3d9.tar.bz2
plus-4dc93e343e0fb4990320e1056bca666e8ce8c3d9.tar.xz
plus-4dc93e343e0fb4990320e1056bca666e8ce8c3d9.zip
fix memory problems with atlases.
Diffstat (limited to 'src/resources/atlasmanager.cpp')
-rw-r--r--src/resources/atlasmanager.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/resources/atlasmanager.cpp b/src/resources/atlasmanager.cpp
index cd3d1d9db..c36d23254 100644
--- a/src/resources/atlasmanager.cpp
+++ b/src/resources/atlasmanager.cpp
@@ -261,6 +261,11 @@ void AtlasManager::convertAtlas(TextureAtlas *atlas)
// convert surface to OpemGL image
atlas->atlasImage = imageHelper->load(atlas->surface);
Image *const image = atlas->atlasImage;
+ if (image)
+ {
+ image->mIdPath = atlas->name;
+ image->incRef();
+ }
for (std::vector<AtlasItem*>::iterator it = atlas->items.begin(),
it_end = atlas->items.end();
@@ -272,6 +277,12 @@ void AtlasManager::convertAtlas(TextureAtlas *atlas)
// store OpenGL image
item->image = image->getSubImage(item->x, item->y,
item->width, item->height);
+ Image *const image2 = item->image;
+ if (image2)
+ {
+ image2->mIdPath = item->name;
+ image2->incRef();
+ }
}
}
@@ -285,7 +296,9 @@ void AtlasManager::injectToResources(AtlasResource *resource)
TextureAtlas *const atlas = *it;
if (atlas)
{
- resman->addResource(atlas->name, atlas->atlasImage);
+ Image *const image = atlas->atlasImage;
+ if (image)
+ resman->addResource(atlas->name, image);
for (std::vector<AtlasItem*>::iterator it2 = atlas->items.begin(),
it2_end = atlas->items.end();
it2 != it2_end; ++ it2)
@@ -349,11 +362,21 @@ AtlasResource::~AtlasResource()
{
AtlasItem *const item = *it2;
if (item)
+ {
+ Image *const image2 = item->image;
+ if (image2)
+ image2->decRef();
delete item;
+ }
}
+ Image *const image = atlas->atlasImage;
+ if (image)
+ image->decRef();
delete atlas;
}
}
+ ResourceManager *const resman = ResourceManager::getInstance();
+ resman->clearDeleted(false);
}
void AtlasResource::incRef()