Fix bank increment never happening due to unsigned overflow

This commit is contained in:
Rangi42
2025-10-07 16:20:24 -04:00
parent cb8c973453
commit 837f552987
7 changed files with 11 additions and 7 deletions

View File

@@ -695,12 +695,6 @@ static void outputUnoptimizedMaps(
uint8_t tileID = 0;
uint8_t bank = 0;
for (AttrmapEntry const &attr : attrmap) {
if (tileID == options.maxNbTiles[bank]) {
assume(bank == 0);
bank = 1;
tileID = 0;
}
if (tilemapOutput.has_value()) {
(*tilemapOutput)
->sputc((attr.isBackgroundTile() ? 0 : tileID) + options.baseTileIDs[bank]);
@@ -714,8 +708,17 @@ static void outputUnoptimizedMaps(
}
// Background tiles are skipped in the tile data, so they should be skipped in the maps too.
if (!attr.isBackgroundTile()) {
if (attr.isBackgroundTile()) {
continue;
}
// Compare with `maxNbTiles` *before* incrementing, due to unsigned overflow!
if (tileID + 1 < options.maxNbTiles[bank]) {
++tileID;
} else {
assume(bank == 0);
bank = 1;
tileID = 0;
}
}
}