Fix assertion failure on nonzero base palette ID without an attribute map or palette map

Also fix palette map IDs to wrap at 256, not at 8 like attributes
This commit is contained in:
Rangi
2026-07-19 23:59:38 -04:00
parent 8d2275dc48
commit 0af28de791
+4 -2
View File
@@ -427,7 +427,7 @@ void reverse() {
// The unsigned underflow for `palOfs` is intentional, since a nonzero
// base palette ID may overflow and continue with IDs from 0.
if (uint8_t palOfs = (palID - options.basePalID) & 0b111; palOfs >= palettes.size()) {
if (uint8_t palOfs = (palID - options.basePalID) & 0xff; palOfs >= palettes.size()) {
error(
"Palette map references palette #%" PRIu8
" at (%zu, %zu), but there %s only %zu palette%s",
@@ -553,7 +553,9 @@ void reverse() {
// This should have been enforced by the earlier checking.
assume(tileOfs < nbTiles + options.trim);
size_t palOfs =
((palmap ? (*palmap)[index] : attribute & 0b111) - options.basePalID) & 0b111;
(palmap ? ((*palmap)[index] - options.basePalID) & 0xff
: attrmap ? (attribute - options.basePalID) & 0b111
: 0);
assume(palOfs < palettes.size()); // Should be ensured on data read
// We do not have data for tiles trimmed with `-x`, so assume they are "blank"