From 7a6b417b8e2b34a5ea4081ad3ccd0860810ebe6e Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 17 Jun 2022 15:47:56 -0400 Subject: [PATCH] Remove UBFIX related to task destruction --- src/battle_anim_sound_tasks.c | 16 ++++++++++------ src/battle_factory_screen.c | 7 +------ src/battle_transition.c | 4 +--- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/battle_anim_sound_tasks.c b/src/battle_anim_sound_tasks.c index 6b14d3863..f329ea210 100644 --- a/src/battle_anim_sound_tasks.c +++ b/src/battle_anim_sound_tasks.c @@ -135,10 +135,12 @@ void SoundTask_PlayCryHighPitch(u8 taskId) { if (gBattleAnimArgs[0] == ANIM_ATTACKER) species = gContestResources->moveAnim->species; - #ifndef UBFIX + // Destroying the task twice (here and at end of function) + // results in an incorrect value for gAnimVisualTaskCount + #ifndef BUGFIX else - DestroyAnimVisualTask(taskId); // UB: task gets destroyed twice. - #endif + DestroyAnimVisualTask(taskId); + #endif } else { @@ -181,10 +183,12 @@ void SoundTask_PlayDoubleCry(u8 taskId) { if (gBattleAnimArgs[0] == ANIM_ATTACKER) species = gContestResources->moveAnim->species; - #ifndef UBFIX + // Destroying the task twice (here and at end of function) + // results in an incorrect value for gAnimVisualTaskCount + #ifndef BUGFIX else - DestroyAnimVisualTask(taskId); // UB: task gets destroyed twice. - #endif + DestroyAnimVisualTask(taskId); + #endif } else { diff --git a/src/battle_factory_screen.c b/src/battle_factory_screen.c index 88e934759..14c63b7b8 100644 --- a/src/battle_factory_screen.c +++ b/src/battle_factory_screen.c @@ -4220,17 +4220,12 @@ static void Task_OpenMonPic(u8 taskId) return; break; default: - #ifndef UBFIX DestroyTask(taskId); - #endif - // UB: Should not use the task after it has been deleted. + // Accessing data of destroyed task. Task data isn't reset until a new task needs that task id. if (gTasks[taskId].tIsSwapScreen == TRUE) Swap_CreateMonSprite(); else Select_CreateMonSprite(); - #ifdef UBFIX - DestroyTask(taskId); - #endif return; } task->tState++; diff --git a/src/battle_transition.c b/src/battle_transition.c index 1e421b5e4..c523cbe7b 100644 --- a/src/battle_transition.c +++ b/src/battle_transition.c @@ -4762,10 +4762,8 @@ static bool8 FrontierSquaresScroll_End(struct Task *task) BlendPalettes(PALETTES_ALL, 16, RGB_BLACK); DestroyTask(FindTaskIdByFunc(task->func)); + task->tState++; // Changing value of a destroyed task -#ifndef UBFIX - task->tState++; // UB: changing value of a destroyed task -#endif return FALSE; }