From 7bcd5113151f6e4cb053d76f90362363dc65fd3a Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 1 Jun 2021 10:11:24 -0300 Subject: [PATCH] Fix crash on debug when painting on removed tiles after resizing the tileset --- src/app/util/cel_ops.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app/util/cel_ops.cpp b/src/app/util/cel_ops.cpp index 3a3f8d1fb..486f83f0d 100644 --- a/src/app/util/cel_ops.cpp +++ b/src/app/util/cel_ops.cpp @@ -783,7 +783,11 @@ static void remove_unused_tiles_from_tileset( const doc::tile_index ti = doc::tile_geti(t); n = std::max(n, ti+1); #ifdef _DEBUG - ++tilesHistogram2[ti]; + // This check is necessary in case the tilemap has a reference + // to a tile outside the valid range (e.g. when we resize the + // tileset deleting tiles that will not be present anymore) + if (ti >= 0 && ti < tilesHistogram2.size()) + ++tilesHistogram2[ti]; #endif } });