From 1820b146c01ec9ab664a5fe28b4e5694e51e7c17 Mon Sep 17 00:00:00 2001 From: arthurtilly <32559225+arthurtilly@users.noreply.github.com> Date: Tue, 19 Jul 2022 23:24:16 +1200 Subject: [PATCH] Fixed memory leak between areas from automatic surface pool size (#452) * fixed mem leak * Add comment to second pop --- src/engine/level_script.c | 3 +++ src/game/area.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/engine/level_script.c b/src/engine/level_script.c index 7e3fa0b9..8256235f 100644 --- a/src/engine/level_script.c +++ b/src/engine/level_script.c @@ -360,6 +360,8 @@ static void level_cmd_clear_level(void) { clear_area_graph_nodes(); clear_areas(); main_pool_pop_state(); + // the game does a push on level load and a pop on level unload, we need to add another push to store state after the level has been loaded, so one more pop is needed + main_pool_pop_state(); unmap_tlbs(); sCurrentCmd = CMD_NEXT; @@ -386,6 +388,7 @@ static void level_cmd_free_level_pool(void) { break; } } + main_pool_push_state(); sCurrentCmd = CMD_NEXT; } diff --git a/src/game/area.c b/src/game/area.c index de8fbce7..ea53b1ca 100644 --- a/src/game/area.c +++ b/src/game/area.c @@ -232,6 +232,8 @@ void load_area(s32 index) { if (gCurrentArea == NULL && gAreaData[index].graphNode != NULL) { gCurrentArea = &gAreaData[index]; gCurrAreaIndex = gCurrentArea->index; + main_pool_pop_state(); + main_pool_push_state(); if (gCurrentArea->terrainData != NULL) { load_area_terrain(index, gCurrentArea->terrainData, gCurrentArea->surfaceRooms,