Merge pull request #1035 from Sierraffinity/master

Document undefined sprite template behavior
This commit is contained in:
Sierra A 2020-05-04 21:14:57 -07:00 committed by GitHub
commit 4dd3cc7b76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 0 deletions

View File

@ -878,12 +878,14 @@ void ResetAllSprites(void)
ResetSprite(&gSprites[i]);
}
// UB: template pointer may point to freed temporary storage
void FreeSpriteTiles(struct Sprite *sprite)
{
if (sprite->template->tileTag != 0xFFFF)
FreeSpriteTilesByTag(sprite->template->tileTag);
}
// UB: template pointer may point to freed temporary storage
void FreeSpritePalette(struct Sprite *sprite)
{
FreeSpritePaletteByTag(sprite->template->paletteTag);

View File

@ -182,6 +182,10 @@ struct SpriteTemplate
SpriteCallback callback;
};
// UB: template pointer is often used to point to temporary storage,
// then later dereferenced after being freed. Usually this won't
// be visible in-game, but this is (part of) what causes the item
// icon palette to flicker when changing items in the bag.
struct Sprite
{
/*0x00*/ struct OamData oam;

View File

@ -484,9 +484,13 @@ static void sub_801B7D8(u32 command)
}
if (dest == NULL)
{
AGB_ASSERT(0);
}
else if (++(*dest) > 999)
{
*dest = 999;
}
}
}