mirror of https://github.com/axmolengine/axmol.git
Merge pull request #11969 from WenhaiLin/v3-TMXTiledMap-crash
TileMap:Fixed crash if referring a non-existent layer in TMX.
This commit is contained in:
commit
27b7f2dd19
|
@ -101,6 +101,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.
|
||||
|
@ -170,6 +173,10 @@ void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
|
|||
if (layerInfo->_visible)
|
||||
{
|
||||
TMXLayer *child = parseLayer(layerInfo, mapInfo);
|
||||
if (child == nullptr) {
|
||||
idx++;
|
||||
continue;
|
||||
}
|
||||
addChild(child, idx, idx);
|
||||
|
||||
// update content size with the max size
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue