From 5ae7076d65e8064d8ae828307a7ad305cf1bade4 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 16 Jun 2021 09:39:42 -0300 Subject: [PATCH] Add extra check/asserts to detect/avoid a reported crash in draw_image_into_new_tilemap_cel (fix #2770) --- src/app/util/cel_ops.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/app/util/cel_ops.cpp b/src/app/util/cel_ops.cpp index 486f83f0d..28200838e 100644 --- a/src/app/util/cel_ops.cpp +++ b/src/app/util/cel_ops.cpp @@ -425,9 +425,15 @@ void draw_image_into_new_tilemap_cel( delete addTile; } - newTilemap->putPixel( - tilePt.x-tilemapBounds.x, - tilePt.y-tilemapBounds.y, tileIndex); + // We were using newTilemap->putPixel() directly but received a + // crash report about an "access violation". So now we've added + // some checks to the operation. + { + const int u = tilePt.x-tilemapBounds.x; + const int v = tilePt.y-tilemapBounds.y; + ASSERT((u >= 0) && (v >= 0) && (u < newTilemap->width()) && (v < newTilemap->height())); + doc::put_pixel(newTilemap.get(), u, v, tileIndex); + } } static_cast(dstLayer->sprite()->document())