From 07f6774cee7cbfe11ebb16811f47f75b82b33c23 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 20 May 2015 11:29:52 +0800 Subject: [PATCH] Crash fix for referring a non-existent layer in tmx. --- cocos/2d/CCTMXTiledMap.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cocos/2d/CCTMXTiledMap.cpp b/cocos/2d/CCTMXTiledMap.cpp index d5a3d842e8..773cf01d24 100644 --- a/cocos/2d/CCTMXTiledMap.cpp +++ b/cocos/2d/CCTMXTiledMap.cpp @@ -102,6 +102,9 @@ TMXTiledMap::~TMXTiledMap() TMXLayer * TMXTiledMap::parseLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo) { TMXTilesetInfo *tileset = tilesetForLayer(layerInfo, mapInfo); + if (tileset == nullptr) + return nullptr; + TMXLayer *layer = TMXLayer::create(tileset, layerInfo, mapInfo); // tell the layerinfo to release the ownership of the tiles map. @@ -171,9 +174,12 @@ void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo) auto& layers = mapInfo->getLayers(); for(const auto &layerInfo : layers) { - if (layerInfo->_visible) - { + if (layerInfo->_visible) { TMXLayer *child = parseLayer(layerInfo, mapInfo); + if (child == nullptr) { + idx++; + continue; + } addChild(child, idx, idx); // update content size with the max size