From 4db4e77c78ae9d1eebb5d92a1f073fc62e2fa11f Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 26 Oct 2020 17:00:05 -0300 Subject: [PATCH] Fix crash deleting all tiles from tileset and remapping --- src/app/ui/color_bar.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/app/ui/color_bar.cpp b/src/app/ui/color_bar.cpp index e28a9f9d2..9ff88e330 100644 --- a/src/app/ui/color_bar.cpp +++ b/src/app/ui/color_bar.cpp @@ -813,17 +813,20 @@ void ColorBar::onRemapTilesButtonClick() doc::Tileset* tileset = m_tilesView.tileset(); std::vector tilemaps; sprite->getTilemapsByTileset(tileset, tilemaps); - PalettePicks usedTiles(tileset->size()); - for (const ImageRef& tilemap : tilemaps) { - for (const doc::tile_t t : LockImageBits(tilemap.get())) - if (t != doc::tile_i_notile) - usedTiles[doc::tile_geti(t)] = true; + const int n = std::max(m_oldTileset->size(), + tileset->size()); + PalettePicks usedTiles(n); + + if (n > 0) { + for (const ImageRef& tilemap : tilemaps) { + for (const doc::tile_t t : LockImageBits(tilemap.get())) + if (t != doc::tile_i_notile) + usedTiles[doc::tile_geti(t)] = true; + } } // Remap all tiles in the same order as in newTileset - const int n = std::max(m_oldTileset->size(), - tileset->size()); Remap remap(n); bool existMapToEmpty = false;