From 1e3c78a4704b87eb24df8e680165cf8d1d4de555 Mon Sep 17 00:00:00 2001 From: Mauro Junior <45118493+jetrotal@users.noreply.github.com> Date: Wed, 15 Jan 2025 15:19:57 -0300 Subject: [PATCH] Rewrite Map: Lock tiles against going OOB. That solves some errors related out of bounds access. Sometimes it happens when drawing a tile, others when checking passability. It may differ from how maniacs deals with this (I suspect maniacs have an extra blank tile, with locked passability, just for OOB tiles). --- src/spriteset_map.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/spriteset_map.cpp b/src/spriteset_map.cpp index e681b343d8..50ea8a8842 100644 --- a/src/spriteset_map.cpp +++ b/src/spriteset_map.cpp @@ -175,13 +175,15 @@ void Spriteset_Map::SubstituteUp(int old_id, int new_id) { } void Spriteset_Map::ReplaceDownAt(int x, int y, int tile_index, bool disable_autotile) { + if (tile_index >= BLOCK_F_INDEX) tile_index = BLOCK_F_INDEX - 1; + auto tile_id = IndexToChipId(tile_index); tilemap->SetMapTileDataDownAt(x, y, tile_id, disable_autotile); } void Spriteset_Map::ReplaceUpAt(int x, int y, int tile_index) { tile_index += BLOCK_F_INDEX; - if (tile_index >= NUM_UPPER_TILES + BLOCK_F_INDEX) tile_index = 0; + if (tile_index >= NUM_UPPER_TILES + BLOCK_F_INDEX) tile_index = BLOCK_F_INDEX; auto tile_id = IndexToChipId(tile_index); tilemap->SetMapTileDataUpAt(x, y, tile_id);