瀏覽代碼

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

Marcus Huderle 6 年之前
父節點
當前提交
d7700b1791
共有 1 個檔案被更改,包括 15 行新增11 行删除
  1. 15
    11
      map.cpp

+ 15
- 11
map.cpp 查看文件

@@ -157,22 +157,26 @@ QImage Map::getMetatileImage(int tile) {
157 157
     for (int x = 0; x < 2; x++) {
158 158
         Tile tile_ = metatile->tiles->value((y * 2) + x + (layer * 4));
159 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 174
         if (layer > 0) {
172 175
             QColor color(tile_image.color(15));
173 176
             color.setAlpha(0);
174 177
             tile_image.setColor(15, color.rgba());
175 178
         }
179
+
176 180
         QPoint origin = QPoint(x*8, y*8);
177 181
         metatile_painter.drawImage(origin, tile_image.mirrored(tile_.xflip == 1, tile_.yflip == 1));
178 182
     }