From 0630acce442ae7a2641a602deb71af4bb8a7c3f7 Mon Sep 17 00:00:00 2001 From: Ariel A <24759293+aarant@users.noreply.github.com> Date: Mon, 27 May 2024 18:09:12 -0400 Subject: [PATCH] fix: make `LoadSheetGraphicsInfo` load, then free, tiles Fixes follower pokeball gfx showing garbage for 1 frame when emerging --- src/event_object_movement.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/event_object_movement.c b/src/event_object_movement.c index b8cfb591b3..686bbdd267 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -1587,10 +1587,12 @@ u16 LoadSheetGraphicsInfo(const struct ObjectEventGraphicsInfo *info, u16 uuid, u32 sheetSpan = GetSpanPerImage(info->oam->shape, info->oam->size); u16 oldTiles = 0; u16 tileStart; + bool32 oldInvisible; if (tag == TAG_NONE) tag = COMP_OW_TILE_TAG_BASE + uuid; if (sprite) { + oldInvisible = sprite->invisible; oldTiles = sprite->sheetTileStart; sprite->sheetTileStart = 0; // mark unused // Note: If sprite was not allocated to use a sheet, @@ -1604,9 +1606,19 @@ u16 LoadSheetGraphicsInfo(const struct ObjectEventGraphicsInfo *info, u16 uuid, if (tileStart == TAG_NONE) { struct SpriteFrameImage image = {.size = info->size, .data = info->images->data}; struct SpriteTemplate template = {.tileTag = tag, .images = &image}; - if (oldTiles) - FieldEffectFreeTilesIfUnused(oldTiles); + // Load, then free, in order to avoid displaying garbage data + // before sprite's `sheetTileStart` is repointed tileStart = LoadCompressedSpriteSheetByTemplate(&template, TILE_SIZE_4BPP << sheetSpan); + if (oldTiles) { + FieldEffectFreeTilesIfUnused(oldTiles); + // We weren't able to load the sheet; + // retry (after having freed), and set sprite to invisible until done + if (tileStart <= 0) { + if (sprite) + sprite->invisible = TRUE; + tileStart = LoadCompressedSpriteSheetByTemplate(&template, TILE_SIZE_4BPP << sheetSpan); + } + } // sheet loaded; unload any *other* sheet for sprite } else if (oldTiles && oldTiles != tileStart) { FieldEffectFreeTilesIfUnused(oldTiles); @@ -1616,6 +1628,7 @@ u16 LoadSheetGraphicsInfo(const struct ObjectEventGraphicsInfo *info, u16 uuid, sprite->sheetTileStart = tileStart; sprite->sheetSpan = sheetSpan; sprite->usingSheet = TRUE; + sprite->invisible = oldInvisible; } // Going from sheet -> !sheet, reset tile number // (sheet stays loaded)