Fix invalid tileset when number of tiles is 0 opening a file

Before this fix, aseprite threw an error: 'Invalid tileset' and delete the Tilemap layer, after it tried to open an aseprite file with a empty tileset on a Tilemap layer.
This commit is contained in:
Gaspar Capello 2020-06-24 16:13:59 -03:00
parent 81b6a99c2c
commit fbe2f8645d

View File

@ -1,5 +1,5 @@
// Aseprite Document IO Library
// Copyright (c) 2018-2019 Igara Studio S.A.
// Copyright (c) 2018-2020 Igara Studio S.A.
// Copyright (c) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
@ -1004,7 +1004,7 @@ void AsepriteDecoder::readTilesetChunk(doc::Sprite* sprite,
const std::string name = readString();
// Errors
if (ntiles < 1 || w < 1 || h < 1) {
if (ntiles < 0 || w < 1 || h < 1) {
delegate()->error(
fmt::format("Error: Invalid tileset (number of tiles={0}, tile size={1}x{2})",
ntiles, w, h));
@ -1032,6 +1032,7 @@ void AsepriteDecoder::readTilesetChunk(doc::Sprite* sprite,
}
if (flags & ASE_TILESET_FLAG_EMBEDDED) {
if (ntiles > 0) {
const size_t dataSize = read32(); // Size of compressed data
const size_t dataBeg = f()->tell();
const size_t dataEnd = dataBeg+dataSize;
@ -1044,7 +1045,7 @@ void AsepriteDecoder::readTilesetChunk(doc::Sprite* sprite,
doc::ImageRef tile(doc::crop_image(alltiles.get(), 0, i*h, w, h, alltiles->maskColor()));
tileset->set(i, tile);
}
}
sprite->tilesets()->set(id, tileset);
}
}