Fix performance issue/lag drawing in 'Auto' mode on a tilemap layer (fix #2877)

We receive a .aseprite example where the tilemap contain some tiles
with huge tile indexes. We don't know why the tilemap was saved with
those wrong values (tile index out of bounds), but it was the cause of
the lag.
This commit is contained in:
Joshua Ogunyinka 2021-09-08 18:47:56 +04:00 committed by David Capello
parent 9e10a1c82c
commit ed8e2c8392

View File

@ -836,6 +836,14 @@ doc::Cel* AsepriteDecoder::readCelChunk(doc::Sprite* sprite,
doc::fix_old_tilemap(image.get(), ts, tileIDMask, flagsMask);
}
// normalize the tile, so its value is never out of bounds
const doc::tile_index tilesetSize = ts->size();
doc::transform_image<doc::TilemapTraits>(
image.get(),
[tilesetSize](const doc::tile_t& tile){
return doc::tile_geti(tile) >= tilesetSize ? doc::notile : tile;
});
cel.reset(new doc::Cel(frame, image));
cel->setPosition(x, y);
cel->setOpacity(opacity);