From 38752b59b42235e020cd32624d36107a2588352a Mon Sep 17 00:00:00 2001 From: psf <77138753+pkmnsnfrn@users.noreply.github.com> Date: Tue, 13 Aug 2024 15:42:39 -0700 Subject: [PATCH] Fix a sprite issue with B_SHOW_TYPES (#5157) * Fixed issue where tiles were not freed * Updated to destroy first * Cleaned up returns * Added typeIconTags Added FreeAllTypeIconResources Fixed issue where typeIcons were not being properly handled when hidden --- src/type_icons.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/type_icons.c b/src/type_icons.c index a36c347775..2877d22071 100644 --- a/src/type_icons.c +++ b/src/type_icons.c @@ -28,6 +28,7 @@ static bool32 ShouldFlipTypeIcon(bool32, u32, u32); static void SpriteCB_TypeIcon(struct Sprite*); static void DestroyTypeIcon(struct Sprite*); +static void FreeAllTypeIconResources(void); static bool32 ShouldHideTypeIcon(u32); static s32 GetTypeIconHideMovement(bool32, u32); static s32 GetTypeIconSlideMovement(bool32, u32, s32); @@ -429,22 +430,45 @@ static void SpriteCB_TypeIcon(struct Sprite* sprite) sprite->y = GetTypeIconBounceMovement(sprite->tVerticalPosition,position); } +static const u32 typeIconTags[] = +{ + TYPE_ICON_TAG, + TYPE_ICON_TAG_2 +}; + static void DestroyTypeIcon(struct Sprite* sprite) { - u32 i; + u32 spriteId, tag; + DestroySpriteAndFreeResources(sprite); - for (i = 0; i < MAX_SPRITES; ++i) + for (spriteId = 0; spriteId < MAX_SPRITES; ++spriteId) { - if (!gSprites[i].inUse) + if (!gSprites[spriteId].inUse) continue; - if (gSprites[i].template->paletteTag == TYPE_ICON_TAG) - return; + for (tag = 0; tag < 2; tag++) + { + if (gSprites[spriteId].template->paletteTag == typeIconTags[tag]) + return; + + if (gSprites[spriteId].template->tileTag == typeIconTags[tag]) + return; + } } - FreeSpritePaletteByTag(TYPE_ICON_TAG); - FreeSpritePaletteByTag(TYPE_ICON_TAG_2); + FreeAllTypeIconResources(); +} + +static void FreeAllTypeIconResources(void) +{ + u32 tag; + + for (tag = 0; tag < 2; tag++) + { + FreeSpriteTilesByTag(typeIconTags[tag]); + FreeSpritePaletteByTag(typeIconTags[tag]); + } } static bool32 ShouldHideTypeIcon(u32 battlerId)