Crash fix for referring a non-existent layer in tmx.

This commit is contained in:
James Chen 2015-05-20 11:29:52 +08:00
parent 5d90a8725e
commit 07f6774cee
1 changed files with 8 additions and 2 deletions

View File

@ -102,6 +102,9 @@ TMXTiledMap::~TMXTiledMap()
TMXLayer * TMXTiledMap::parseLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo) TMXLayer * TMXTiledMap::parseLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo)
{ {
TMXTilesetInfo *tileset = tilesetForLayer(layerInfo, mapInfo); TMXTilesetInfo *tileset = tilesetForLayer(layerInfo, mapInfo);
if (tileset == nullptr)
return nullptr;
TMXLayer *layer = TMXLayer::create(tileset, layerInfo, mapInfo); TMXLayer *layer = TMXLayer::create(tileset, layerInfo, mapInfo);
// tell the layerinfo to release the ownership of the tiles map. // tell the layerinfo to release the ownership of the tiles map.
@ -171,9 +174,12 @@ void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
auto& layers = mapInfo->getLayers(); auto& layers = mapInfo->getLayers();
for(const auto &layerInfo : layers) { for(const auto &layerInfo : layers) {
if (layerInfo->_visible) if (layerInfo->_visible) {
{
TMXLayer *child = parseLayer(layerInfo, mapInfo); TMXLayer *child = parseLayer(layerInfo, mapInfo);
if (child == nullptr) {
idx++;
continue;
}
addChild(child, idx, idx); addChild(child, idx, idx);
// update content size with the max size // update content size with the max size