diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-09-01 20:19:16 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-09-01 20:19:16 +0300 |
commit | abeb235bfdc013ac621615ed84984e033efa42d5 (patch) | |
tree | f23f1ba4d31ea9dba07ff226a00ee42fc99dfaa3 /src | |
parent | 375a55d84aaa112132cf4056dddb81c29cc47455 (diff) | |
download | manaplus-abeb235bfdc013ac621615ed84984e033efa42d5.tar.gz manaplus-abeb235bfdc013ac621615ed84984e033efa42d5.tar.bz2 manaplus-abeb235bfdc013ac621615ed84984e033efa42d5.tar.xz manaplus-abeb235bfdc013ac621615ed84984e033efa42d5.zip |
Add asserts into AtlasManager and fix null pointer access if some error happened.
Diffstat (limited to 'src')
-rw-r--r-- | src/resources/atlas/atlasmanager.cpp | 20 |
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") |