Skip to content

Commit

Permalink
Fixed Fusion memory leak (rh-hideout#3644)
Browse files Browse the repository at this point in the history
* Fixed Fusion memory leak

* using u32

---------

Co-authored-by: Bassoonian <[email protected]>
  • Loading branch information
2 people authored and PCG06 committed Dec 8, 2023
1 parent 262d2f0 commit 1d174f2
Showing 1 changed file with 29 additions and 41 deletions.
70 changes: 29 additions & 41 deletions src/party_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ static void ExitPartyMenu(void);
static bool8 AllocPartyMenuBg(void);
static bool8 AllocPartyMenuBgGfx(void);
static void InitPartyMenuWindows(u8);
static void LoadPartyMenuWindows(void);
static void InitPartyMenuBoxes(u8);
static void LoadPartyMenuBoxes(u8);
static void LoadPartyMenuPokeballGfx(void);
static bool8 CreatePartyMonSpritesLoop(void);
static bool8 RenderPartyMenuBoxes(void);
Expand Down Expand Up @@ -569,17 +571,10 @@ static void InitPartyMenu(u8 menuType, u8 layout, u8 partyAction, bool8 keepCurs
static void RefreshPartyMenu(void) //Refreshes the party menu without restarting tasks
{
u16 i;

sPartyMenuInternal->exitCallback = NULL;
sPartyMenuInternal->lastSelectedSlot = 0;
sPartyMenuInternal->spriteIdConfirmPokeball = 0x7F;
sPartyMenuInternal->spriteIdCancelPokeball = 0x7F;

for (i = 0; i < ARRAY_COUNT(sPartyMenuInternal->data); i++)
sPartyMenuInternal->data[i] = 0;
for (i = 0; i < ARRAY_COUNT(sPartyMenuInternal->windowId); i++)
sPartyMenuInternal->windowId[i] = WINDOW_NONE;

gTextFlags.autoScroll = 0;
CalculatePlayerPartyCount();
SetMainCallback2(CB2_ReloadPartyMenu);
Expand Down Expand Up @@ -774,77 +769,62 @@ static bool8 ReloadPartyMenu(void)
gMain.state++;
break;
case 6:
if (!AllocPartyMenuBg())
{
ExitPartyMenu();
return TRUE;
}
else
{
sPartyMenuInternal->data[0] = 0;
gMain.state++;
}
sPartyMenuInternal->data[0] = 0;
gMain.state++;
break;
case 7:
if (AllocPartyMenuBgGfx())
gMain.state++;
break;
case 8:
InitPartyMenuWindows(gPartyMenu.layout);
LoadPartyMenuWindows();
gMain.state++;
break;
case 9:
InitPartyMenuBoxes(gPartyMenu.layout);
case 8:
LoadPartyMenuBoxes(gPartyMenu.layout);
sPartyMenuInternal->data[0] = 0;
gMain.state++;
break;
case 10:
case 9:
LoadHeldItemIcons();
gMain.state++;
break;
case 11:
case 10:
LoadPartyMenuPokeballGfx();
gMain.state++;
break;
case 12:
case 11:
LoadPartyMenuAilmentGfx();
gMain.state++;
break;
case 13:
case 12:
LoadMonIconPalettes();
gMain.state++;
break;
case 14:
case 13:
if (CreatePartyMonSpritesLoop())
{
sPartyMenuInternal->data[0] = 0;
gMain.state++;
}
break;
case 15:
case 14:
if (RenderPartyMenuBoxes())
{
sPartyMenuInternal->data[0] = 0;
gMain.state++;
}
break;
case 16:
case 15:
CreateCancelConfirmPokeballSprites();
gMain.state++;
break;
case 17:
case 16:
CreateCancelConfirmWindows(sPartyMenuInternal->chooseHalf);
gMain.state++;
break;
case 18:
gMain.state++;
break;
case 19:
case 17:
BlendPalettes(PALETTES_ALL, 16, RGB_WHITEALPHA);
gPaletteFade.bufferTransferDisabled = FALSE;
gMain.state++;
break;
case 20:
case 18:
BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_WHITEALPHA);
gMain.state++;
break;
Expand Down Expand Up @@ -973,9 +953,13 @@ static void FreePartyPointers(void)

static void InitPartyMenuBoxes(u8 layout)
{
u8 i;

sPartyMenuBoxes = Alloc(sizeof(struct PartyMenuBox[PARTY_SIZE]));
LoadPartyMenuBoxes(layout);
}

static void LoadPartyMenuBoxes(u8 layout)
{
u32 i;

for (i = 0; i < PARTY_SIZE; i++)
{
Expand Down Expand Up @@ -2275,8 +2259,6 @@ static u8 CanTeachMove(struct Pokemon *mon, u16 move)

static void InitPartyMenuWindows(u8 layout)
{
u8 i;

switch (layout)
{
case PARTY_LAYOUT_SINGLE:
Expand All @@ -2292,6 +2274,12 @@ static void InitPartyMenuWindows(u8 layout)
InitWindows(sShowcaseMultiPartyMenuWindowTemplate);
break;
}
LoadPartyMenuWindows();
}

static void LoadPartyMenuWindows(void)
{
u32 i;
DeactivateAllTextPrinters();
for (i = 0; i < PARTY_SIZE; i++)
FillWindowPixelBuffer(i, PIXEL_FILL(0));
Expand Down

0 comments on commit 1d174f2

Please sign in to comment.