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++) {
|
||||
Tile tile_ = metatile->tiles->value((y * 2) + x + (layer * 4));
|
||||
QImage tile_image = getMetatileTile(tile_.tile);
|
||||
//if (tile_image.isNull()) {
|
||||
// continue;
|
||||
//}
|
||||
//if (blockTileset->palettes) {
|
||||
QList<QRgb> palette = palettes.value(tile_.palette);
|
||||
for (int j = 0; j < palette.length(); j++) {
|
||||
tile_image.setColor(j, palette.value(j));
|
||||
}
|
||||
//}
|
||||
//QVector<QRgb> vector = palette.toVector();
|
||||
//tile_image.setColorTable(vector);
|
||||
if (tile_image.isNull()) {
|
||||
// Some metatiles specify tiles that are outside the valid range.
|
||||
// These are treated as completely transparent, so they can be skipped without
|
||||
// being drawn.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Colorize the metatile tiles with its palette.
|
||||
QList<QRgb> palette = palettes.value(tile_.palette);
|
||||
for (int j = 0; j < palette.length(); j++) {
|
||||
tile_image.setColor(j, palette.value(j));
|
||||
}
|
||||
|
||||
// The top layer of the metatile has its last color displayed at transparent.
|
||||
if (layer > 0) {
|
||||
QColor color(tile_image.color(15));
|
||||
color.setAlpha(0);
|
||||
tile_image.setColor(15, color.rgba());
|
||||
}
|
||||
|
||||
QPoint origin = QPoint(x*8, y*8);
|
||||
metatile_painter.drawImage(origin, tile_image.mirrored(tile_.xflip == 1, tile_.yflip == 1));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue