Fix crash that was caused by out-of-bounds metatile tiles
This commit is contained in:
parent
631dac5839
commit
d7700b1791
1 changed files with 15 additions and 11 deletions
26
map.cpp
26
map.cpp
|
@ -157,22 +157,26 @@ QImage Map::getMetatileImage(int tile) {
|
||||||
for (int x = 0; x < 2; x++) {
|
for (int x = 0; x < 2; x++) {
|
||||||
Tile tile_ = metatile->tiles->value((y * 2) + x + (layer * 4));
|
Tile tile_ = metatile->tiles->value((y * 2) + x + (layer * 4));
|
||||||
QImage tile_image = getMetatileTile(tile_.tile);
|
QImage tile_image = getMetatileTile(tile_.tile);
|
||||||
//if (tile_image.isNull()) {
|
if (tile_image.isNull()) {
|
||||||
// continue;
|
// Some metatiles specify tiles that are outside the valid range.
|
||||||
//}
|
// These are treated as completely transparent, so they can be skipped without
|
||||||
//if (blockTileset->palettes) {
|
// being drawn.
|
||||||
QList<QRgb> palette = palettes.value(tile_.palette);
|
continue;
|
||||||
for (int j = 0; j < palette.length(); j++) {
|
}
|
||||||
tile_image.setColor(j, palette.value(j));
|
|
||||||
}
|
// Colorize the metatile tiles with its palette.
|
||||||
//}
|
QList<QRgb> palette = palettes.value(tile_.palette);
|
||||||
//QVector<QRgb> vector = palette.toVector();
|
for (int j = 0; j < palette.length(); j++) {
|
||||||
//tile_image.setColorTable(vector);
|
tile_image.setColor(j, palette.value(j));
|
||||||
|
}
|
||||||
|
|
||||||
|
// The top layer of the metatile has its last color displayed at transparent.
|
||||||
if (layer > 0) {
|
if (layer > 0) {
|
||||||
QColor color(tile_image.color(15));
|
QColor color(tile_image.color(15));
|
||||||
color.setAlpha(0);
|
color.setAlpha(0);
|
||||||
tile_image.setColor(15, color.rgba());
|
tile_image.setColor(15, color.rgba());
|
||||||
}
|
}
|
||||||
|
|
||||||
QPoint origin = QPoint(x*8, y*8);
|
QPoint origin = QPoint(x*8, y*8);
|
||||||
metatile_painter.drawImage(origin, tile_image.mirrored(tile_.xflip == 1, tile_.yflip == 1));
|
metatile_painter.drawImage(origin, tile_image.mirrored(tile_.xflip == 1, tile_.yflip == 1));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue