Add sanity checks to setMetatileLayerOrder

This commit is contained in:
GriffinR 2022-07-02 15:52:34 -04:00 committed by Marcus Huderle
parent d86d388db8
commit 3a2d2ef3c2
2 changed files with 18 additions and 1 deletions

View file

@ -794,6 +794,23 @@ QList<int> MainWindow::getMetatileLayerOrder() {
void MainWindow::setMetatileLayerOrder(QList<int> order) {
if (!this->editor || !this->editor->map)
return;
const int numLayers = 3;
int size = order.size();
if (size < numLayers) {
logError(QString("Metatile layer order has insufficient elements (%1), needs at least %2.").arg(size).arg(numLayers));
return;
}
bool invalid = false;
for (int i = 0; i < numLayers; i++) {
int layer = order.at(i);
if (layer < 0 || layer >= numLayers) {
logError(QString("'%1' is not a valid metatile layer order value, must be in range 0-%2.").arg(layer).arg(numLayers - 1));
invalid = true;
}
}
if (invalid) return;
this->editor->map->metatileLayerOrder = order;
this->refreshAfterPalettePreviewChange();
}

View file

@ -56,7 +56,7 @@ QImage getMetatileImage(
for (int layer = 0; layer < numLayers; layer++)
for (int y = 0; y < 2; y++)
for (int x = 0; x < 2; x++) {
int l = layerOrder.size() >= numLayers ? (layerOrder[layer] % numLayers) : layer;
int l = layerOrder.size() >= numLayers ? layerOrder[layer] : layer;
int bottomLayer = layerOrder.size() >= numLayers ? layerOrder[0] : 0;
// Get the tile to render next