Skip to content

Commit

Permalink
Rewrite Map: Lock tiles against going OOB.
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
jetrotal committed Jan 15, 2025
1 parent 8bcba94 commit 1e3c78a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/spriteset_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1e3c78a

Please sign in to comment.