Skip to content

Commit a87ccd1

Browse files
committed
Fix Stage Warp crash
1 parent 9e18bfb commit a87ccd1

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/game/code_1_3.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,12 +2261,12 @@ void TaskDestructor_8056104(Task *t)
22612261
VramFree(temp_r4->s2.tiles);
22622262
}
22632263

2264-
void sub_8056120(u16 arg0)
2264+
void sub_8056120(u16 levelId)
22652265
{
22662266
Strc_10_8056120 *strc;
22672267

22682268
strc = TASK_DATA(TaskCreate(Task_10_8056984, sizeof(Strc_10_8056120), 0x100U, 0U, NULL));
2269-
strc->levelId = arg0;
2269+
strc->levelId = levelId;
22702270
strc->fade.window = 0;
22712271
strc->fade.flags = 1;
22722272
strc->fade.brightness = 0;
@@ -2732,11 +2732,20 @@ void Task_8056A20(void)
27322732
void Task_10_8056A58(void)
27332733
{
27342734
Strc_10_8056120 *strc10 = TASK_DATA(gCurTask);
2735+
#ifdef BUG_FIX
2736+
// BUG: Use-after-free.
2737+
// Retrieve the value before destroying the task.
2738+
u16 levelId = strc10->levelId;
2739+
#endif
27352740

27362741
TasksDestroyAll();
27372742
PAUSE_BACKGROUNDS_QUEUE();
27382743
gBgSpritesCount = 0;
27392744
PAUSE_GRAPHICS_QUEUE();
27402745

2746+
#ifndef BUG_FIX
27412747
WarpToMap(strc10->levelId, 0);
2748+
#else
2749+
WarpToMap(levelId, 0);
2750+
#endif
27422751
}

src/platform/shared/stub.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ u8 gUnknown_03006C20 = 0;
4141

4242
void Stop() { }
4343

44-
void CreateChaoMap() { }
4544
s16 sub_8023E04() { return 0; }
4645
bool32 sub_8023E80(void) { return FALSE; }
4746
u16 sub_8023EFC(void) { return 0; }

0 commit comments

Comments
 (0)