Fix when picture file used by TMX map file missing or broken, create TMX object will cause program crashed

This commit is contained in:
XiaoFeng 2015-08-19 14:02:12 +08:00
parent b9fa482672
commit f26509efe4
2 changed files with 9 additions and 3 deletions

View File

@ -61,6 +61,9 @@ bool TMXLayer::initWithTilesetInfo(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *la
texture = Director::getInstance()->getTextureCache()->addImage(tilesetInfo->_sourceImage.c_str());
}
if (nullptr == texture)
return false;
if (SpriteBatchNode::initWithTexture(texture, static_cast<ssize_t>(capacity)))
{
// layerInfo

View File

@ -107,9 +107,12 @@ TMXLayer * TMXTiledMap::parseLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo)
TMXLayer *layer = TMXLayer::create(tileset, layerInfo, mapInfo);
// tell the layerinfo to release the ownership of the tiles map.
layerInfo->_ownTiles = false;
layer->setupTiles();
if (nullptr != layer)
{
// tell the layerinfo to release the ownership of the tiles map.
layerInfo->_ownTiles = false;
layer->setupTiles();
}
return layer;
}