summaryrefslogtreecommitdiff
path: root/src/resources/atlas
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-09-01 20:19:16 +0300
committerAndrei Karas <akaras@inbox.ru>2016-09-01 20:19:16 +0300
commitabeb235bfdc013ac621615ed84984e033efa42d5 (patch)
treef23f1ba4d31ea9dba07ff226a00ee42fc99dfaa3 /src/resources/atlas
parent375a55d84aaa112132cf4056dddb81c29cc47455 (diff)
downloadplus-abeb235bfdc013ac621615ed84984e033efa42d5.tar.gz
plus-abeb235bfdc013ac621615ed84984e033efa42d5.tar.bz2
plus-abeb235bfdc013ac621615ed84984e033efa42d5.tar.xz
plus-abeb235bfdc013ac621615ed84984e033efa42d5.zip
Add asserts into AtlasManager and fix null pointer access if some error happened.
Diffstat (limited to 'src/resources/atlas')
-rw-r--r--src/resources/atlas/atlasmanager.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/resources/atlas/atlasmanager.cpp b/src/resources/atlas/atlasmanager.cpp
index 19ab3b09f..33af47070 100644
--- a/src/resources/atlas/atlasmanager.cpp
+++ b/src/resources/atlas/atlasmanager.cpp
@@ -80,6 +80,8 @@ AtlasResource *AtlasManager::loadTextureAtlas(const std::string &name,
continue;
createSDLAtlas(atlas);
+ if (atlas->atlasImage == nullptr)
+ continue;
convertAtlas(atlas);
resource->atlases.push_back(atlas);
}
@@ -284,6 +286,7 @@ void AtlasManager::createSDLAtlas(TextureAtlas *const atlas)
// do not create atlas based on only one image
if (atlas->items.size() == 1)
{
+ logger->log("Skip atlas creation because only one image in atlas.");
BLOCK_END("AtlasManager::createSDLAtlas")
return;
}
@@ -300,6 +303,9 @@ void AtlasManager::createSDLAtlas(TextureAtlas *const atlas)
width, height, 32U, rmask, gmask, bmask, amask);
if (!surface)
{
+ reportAlways("Error creating surface for atlas. Size: %dx%d",
+ width,
+ height);
BLOCK_END("AtlasManager::createSDLAtlas")
return;
}
@@ -308,16 +314,20 @@ void AtlasManager::createSDLAtlas(TextureAtlas *const atlas)
Image *image = imageHelper->loadSurface(surface);
// free SDL atlas surface
MSDL_FreeSurface(surface);
+ if (image == nullptr)
+ {
+ reportAlways("Error converting surface to texture. Size: %dx%d",
+ width,
+ height);
+ return;
+ }
// drawing SDL images to surface
FOR_EACH (std::vector<AtlasItem*>::iterator, it, atlas->items)
{
AtlasItem *const item = *it;
- if (image)
- {
- imageHelper->copySurfaceToImage(image, item->x, item->y,
- item->image->mSDLSurface);
- }
+ imageHelper->copySurfaceToImage(image, item->x, item->y,
+ item->image->mSDLSurface);
}
atlas->atlasImage = image;
BLOCK_END("AtlasManager::createSDLAtlas")