Browse Source

Fix crash that was caused by out-of-bounds metatile tiles

Marcus Huderle 6 years ago
parent
commit
d7700b1791
1 changed files with 15 additions and 11 deletions
  1. 15
    11
      map.cpp

+ 15
- 11
map.cpp View File

157
     for (int x = 0; x < 2; x++) {
157
     for (int x = 0; x < 2; x++) {
158
         Tile tile_ = metatile->tiles->value((y * 2) + x + (layer * 4));
158
         Tile tile_ = metatile->tiles->value((y * 2) + x + (layer * 4));
159
         QImage tile_image = getMetatileTile(tile_.tile);
159
         QImage tile_image = getMetatileTile(tile_.tile);
160
-        //if (tile_image.isNull()) {
161
-        //    continue;
162
-        //}
163
-        //if (blockTileset->palettes) {
164
-            QList<QRgb> palette = palettes.value(tile_.palette);
165
-            for (int j = 0; j < palette.length(); j++) {
166
-                tile_image.setColor(j, palette.value(j));
167
-            }
168
-        //}
169
-        //QVector<QRgb> vector = palette.toVector();
170
-        //tile_image.setColorTable(vector);
160
+        if (tile_image.isNull()) {
161
+            // Some metatiles specify tiles that are outside the valid range.
162
+            // These are treated as completely transparent, so they can be skipped without
163
+            // being drawn.
164
+            continue;
165
+        }
166
+
167
+        // Colorize the metatile tiles with its palette.
168
+        QList<QRgb> palette = palettes.value(tile_.palette);
169
+        for (int j = 0; j < palette.length(); j++) {
170
+            tile_image.setColor(j, palette.value(j));
171
+        }
172
+
173
+        // The top layer of the metatile has its last color displayed at transparent.
171
         if (layer > 0) {
174
         if (layer > 0) {
172
             QColor color(tile_image.color(15));
175
             QColor color(tile_image.color(15));
173
             color.setAlpha(0);
176
             color.setAlpha(0);
174
             tile_image.setColor(15, color.rgba());
177
             tile_image.setColor(15, color.rgba());
175
         }
178
         }
179
+
176
         QPoint origin = QPoint(x*8, y*8);
180
         QPoint origin = QPoint(x*8, y*8);
177
         metatile_painter.drawImage(origin, tile_image.mirrored(tile_.xflip == 1, tile_.yflip == 1));
181
         metatile_painter.drawImage(origin, tile_image.mirrored(tile_.xflip == 1, tile_.yflip == 1));
178
     }
182
     }