From abeb235bfdc013ac621615ed84984e033efa42d5 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 1 Sep 2016 20:19:16 +0300 Subject: Add asserts into AtlasManager and fix null pointer access if some error happened. --- src/resources/atlas/atlasmanager.cpp | 20 +++++++++++++++----- 1 file 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::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") -- cgit v1.2.3-70-g09d2