mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-16 05:42:32 +00:00
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:
parent
81b6a99c2c
commit
fbe2f8645d
@ -1,5 +1,5 @@
|
|||||||
// Aseprite Document IO Library
|
// 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
|
// Copyright (c) 2001-2018 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// 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();
|
const std::string name = readString();
|
||||||
|
|
||||||
// Errors
|
// Errors
|
||||||
if (ntiles < 1 || w < 1 || h < 1) {
|
if (ntiles < 0 || w < 1 || h < 1) {
|
||||||
delegate()->error(
|
delegate()->error(
|
||||||
fmt::format("Error: Invalid tileset (number of tiles={0}, tile size={1}x{2})",
|
fmt::format("Error: Invalid tileset (number of tiles={0}, tile size={1}x{2})",
|
||||||
ntiles, w, h));
|
ntiles, w, h));
|
||||||
@ -1032,19 +1032,20 @@ void AsepriteDecoder::readTilesetChunk(doc::Sprite* sprite,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (flags & ASE_TILESET_FLAG_EMBEDDED) {
|
if (flags & ASE_TILESET_FLAG_EMBEDDED) {
|
||||||
const size_t dataSize = read32(); // Size of compressed data
|
if (ntiles > 0) {
|
||||||
const size_t dataBeg = f()->tell();
|
const size_t dataSize = read32(); // Size of compressed data
|
||||||
const size_t dataEnd = dataBeg+dataSize;
|
const size_t dataBeg = f()->tell();
|
||||||
|
const size_t dataEnd = dataBeg+dataSize;
|
||||||
|
|
||||||
doc::ImageRef alltiles(doc::Image::create(sprite->pixelFormat(), w, h*ntiles));
|
doc::ImageRef alltiles(doc::Image::create(sprite->pixelFormat(), w, h*ntiles));
|
||||||
read_compressed_image(f(), delegate(), alltiles.get(), header, dataEnd);
|
read_compressed_image(f(), delegate(), alltiles.get(), header, dataEnd);
|
||||||
f()->seek(dataEnd);
|
f()->seek(dataEnd);
|
||||||
|
|
||||||
for (doc::tile_index i=0; i<ntiles; ++i) {
|
for (doc::tile_index i=0; i<ntiles; ++i) {
|
||||||
doc::ImageRef tile(doc::crop_image(alltiles.get(), 0, i*h, w, h, alltiles->maskColor()));
|
doc::ImageRef tile(doc::crop_image(alltiles.get(), 0, i*h, w, h, alltiles->maskColor()));
|
||||||
tileset->set(i, tile);
|
tileset->set(i, tile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sprite->tilesets()->set(id, tileset);
|
sprite->tilesets()->set(id, tileset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user