Add vlidation for metatile id range

This commit is contained in:
Marcus Huderle 2022-09-10 12:33:25 -05:00
parent b715e43ba8
commit b14d8b8a88

View file

@ -69,11 +69,14 @@ void Prefab::loadPrefabs() {
if (x < 0 || x >= width || y < 0 || y >= height) if (x < 0 || x >= width || y < 0 || y >= height)
continue; continue;
int index = y * width + x; int index = y * width + x;
selection.metatileItems[index].enabled = true; int metatileId = metatileObj["metatile_id"].toInt();
if (metatileId < 0 || metatileId >= Project::getNumMetatilesTotal())
continue;
selection.metatileItems[index].metatileId = metatileObj["metatile_id"].toInt(); selection.metatileItems[index].metatileId = metatileObj["metatile_id"].toInt();
selection.collisionItems[index].enabled = true;
selection.collisionItems[index].collision = metatileObj["collision"].toInt(); selection.collisionItems[index].collision = metatileObj["collision"].toInt();
selection.collisionItems[index].elevation = metatileObj["elevation"].toInt(); selection.collisionItems[index].elevation = metatileObj["elevation"].toInt();
selection.metatileItems[index].enabled = true;
selection.collisionItems[index].enabled = true;
} }
this->items.append(PrefabItem{QUuid::createUuid(), name, primaryTileset, secondaryTileset, selection}); this->items.append(PrefabItem{QUuid::createUuid(), name, primaryTileset, secondaryTileset, selection});