Use the TRY_FREE_AND_SET_NULL macro where appropriate

This commit is contained in:
sphericalice 2022-06-03 15:42:53 +01:00
parent a7b6dfee3a
commit d03756dfd2
10 changed files with 24 additions and 53 deletions

View File

@ -1131,8 +1131,7 @@ static void CB2_InitSelectScreen(void)
switch (gMain.state)
{
case 0:
if (sFactorySelectMons != NULL)
FREE_AND_SET_NULL(sFactorySelectMons);
TRY_FREE_AND_SET_NULL(sFactorySelectMons);
SetHBlankCallback(NULL);
SetVBlankCallback(NULL);
CpuFill32(0, (void *)VRAM, VRAM_SIZE);

View File

@ -1672,8 +1672,7 @@ static bool8 InitEasyChatScreenStruct(u8 type, u16 *words, u8 displayedPersonTyp
static void FreeEasyChatScreenStruct(void)
{
if (sEasyChatScreen != NULL)
FREE_AND_SET_NULL(sEasyChatScreen);
TRY_FREE_AND_SET_NULL(sEasyChatScreen);
}
// Returns the function ID of the action to take as a result of player's input.
@ -3075,8 +3074,7 @@ static bool8 LoadEasyChatScreen(void)
static void FreeEasyChatScreenControl(void)
{
if (sScreenControl)
FREE_AND_SET_NULL(sScreenControl);
TRY_FREE_AND_SET_NULL(sScreenControl);
}
static void StartEasyChatFunction(u16 funcId)
@ -5573,8 +5571,7 @@ static bool8 InitEasyChatScreenWordData(void)
static void FreeEasyChatScreenWordData(void)
{
if (sWordData)
FREE_AND_SET_NULL(sWordData);
TRY_FREE_AND_SET_NULL(sWordData);
}
static void SetUnlockedEasyChatGroups(void)

View File

@ -192,10 +192,7 @@ static void FieldUpdateRegionMap(void)
{
FreeRegionMapIconResources();
SetMainCallback2(sFieldRegionMapHandler->callback);
if (sFieldRegionMapHandler != NULL)
{
FREE_AND_SET_NULL(sFieldRegionMapHandler);
}
TRY_FREE_AND_SET_NULL(sFieldRegionMapHandler);
FreeAllWindowBuffers();
}
break;

View File

@ -529,10 +529,8 @@ static void Task_Hof_TrySaveData(u8 taskId)
UnsetBgTilemapBuffer(3);
FreeAllWindowBuffers();
if (sHofGfxPtr != NULL)
FREE_AND_SET_NULL(sHofGfxPtr);
if (sHofMonPtr != NULL)
FREE_AND_SET_NULL(sHofMonPtr);
TRY_FREE_AND_SET_NULL(sHofGfxPtr);
TRY_FREE_AND_SET_NULL(sHofMonPtr);
DestroyTask(taskId);
}
@ -773,10 +771,8 @@ static void Task_Hof_HandleExit(u8 taskId)
ResetBgsAndClearDma3BusyFlags(0);
DestroyTask(taskId);
if (sHofGfxPtr != NULL)
FREE_AND_SET_NULL(sHofGfxPtr);
if (sHofMonPtr != NULL)
FREE_AND_SET_NULL(sHofMonPtr);
TRY_FREE_AND_SET_NULL(sHofGfxPtr);
TRY_FREE_AND_SET_NULL(sHofMonPtr);
StartCredits();
}
@ -1081,10 +1077,8 @@ static void Task_HofPC_HandleExit(u8 taskId)
ResetBgsAndClearDma3BusyFlags(0);
DestroyTask(taskId);
if (sHofGfxPtr != NULL)
FREE_AND_SET_NULL(sHofGfxPtr);
if (sHofMonPtr != NULL)
FREE_AND_SET_NULL(sHofMonPtr);
TRY_FREE_AND_SET_NULL(sHofGfxPtr);
TRY_FREE_AND_SET_NULL(sHofMonPtr);
ReturnFromHallOfFamePC();
}

View File

@ -5417,8 +5417,7 @@ static bool32 WaitForWallpaperGfxLoad(void)
if (IsDma3ManagerBusyWithBgCopy())
return FALSE;
if (sStorage->wallpaperTiles != NULL)
FREE_AND_SET_NULL(sStorage->wallpaperTiles);
TRY_FREE_AND_SET_NULL(sStorage->wallpaperTiles);
return TRUE;
}

View File

@ -557,8 +557,7 @@ void *GetSubstructPtr(u32 index)
void FreePokenavSubstruct(u32 index)
{
if (gPokenavResources->substructPtrs[index] != NULL)
FREE_AND_SET_NULL(gPokenavResources->substructPtrs[index]);
TRY_FREE_AND_SET_NULL(gPokenavResources->substructPtrs[index]);
}
u32 GetPokenavMode(void)

View File

@ -2024,11 +2024,7 @@ static void CB_ExitFlyMap(void)
{
SetMainCallback2(CB2_ReturnToPartyMenuFromFlyMap);
}
if (sFlyMap != NULL)
{
free(sFlyMap);
sFlyMap = NULL;
}
TRY_FREE_AND_SET_NULL(sFlyMap);
FreeAllWindowBuffers();
}
break;

View File

@ -101,8 +101,7 @@ void FreeRotatingTilePuzzle(void)
{
u8 id;
if (sRotatingTilePuzzle != NULL)
FREE_AND_SET_NULL(sRotatingTilePuzzle);
TRY_FREE_AND_SET_NULL(sRotatingTilePuzzle);
id = GetObjectEventIdByLocalIdAndMap(OBJ_EVENT_ID_PLAYER, 0, 0);
ObjectEventClearHeldMovementIfFinished(&gObjectEvents[id]);

View File

@ -1756,14 +1756,10 @@ static bool8 SlotTask_FreeDataStructures(struct Task *task)
FREE_AND_SET_NULL(sImageTable_DigitalDisplay_Number);
FREE_AND_SET_NULL(sImageTable_DigitalDisplay_Pokeball);
FREE_AND_SET_NULL(sImageTable_DigitalDisplay_DPad);
if (sImageTable_ReelTimePikachu != NULL)
FREE_AND_SET_NULL(sImageTable_ReelTimePikachu);
if (sImageTable_ReelTimeMachineAntennae != NULL)
FREE_AND_SET_NULL(sImageTable_ReelTimeMachineAntennae);
if (sImageTable_ReelTimeMachine != NULL)
FREE_AND_SET_NULL(sImageTable_ReelTimeMachine);
if (sImageTable_BrokenReelTimeMachine != NULL)
FREE_AND_SET_NULL(sImageTable_BrokenReelTimeMachine);
TRY_FREE_AND_SET_NULL(sImageTable_ReelTimePikachu);
TRY_FREE_AND_SET_NULL(sImageTable_ReelTimeMachineAntennae);
TRY_FREE_AND_SET_NULL(sImageTable_ReelTimeMachine);
TRY_FREE_AND_SET_NULL(sImageTable_BrokenReelTimeMachine);
FREE_AND_SET_NULL(sMenuGfx);
FREE_AND_SET_NULL(sSelectedPikaPowerTile);
FREE_AND_SET_NULL(sReelOverlay_Tilemap);
@ -4178,8 +4174,7 @@ static void CreateReelTimePikachuSprite(void)
static void DestroyReelTimePikachuSprite(void)
{
DestroySprite(&gSprites[sSlotMachine->reelTimePikachuSpriteId]);
if (sImageTable_ReelTimePikachu != NULL)
FREE_AND_SET_NULL(sImageTable_ReelTimePikachu);
TRY_FREE_AND_SET_NULL(sImageTable_ReelTimePikachu);
}
static void SpriteCB_ReelTimePikachu(struct Sprite *sprite)
@ -4308,10 +4303,8 @@ static void DestroyReelTimeMachineSprites(void)
for (i = 0; i < ARRAY_COUNT(sSlotMachine->reelTimeMachineSpriteIds); i++)
DestroySprite(&gSprites[sSlotMachine->reelTimeMachineSpriteIds[i]]);
if (sImageTable_ReelTimeMachineAntennae != NULL)
FREE_AND_SET_NULL(sImageTable_ReelTimeMachineAntennae);
if (sImageTable_ReelTimeMachine != NULL)
FREE_AND_SET_NULL(sImageTable_ReelTimeMachine);
TRY_FREE_AND_SET_NULL(sImageTable_ReelTimeMachineAntennae);
TRY_FREE_AND_SET_NULL(sImageTable_ReelTimeMachine);
for (i = 0; i < ARRAY_COUNT(sSlotMachine->reelTimeNumberSpriteIds); i++)
DestroySprite(&gSprites[sSlotMachine->reelTimeNumberSpriteIds[i]]);
@ -4328,8 +4321,7 @@ static void DestroyReelTimeShadowSprites(void)
static void DestroyBrokenReelTimeMachineSprite(void)
{
DestroySprite(&gSprites[sSlotMachine->reelTimeBrokenMachineSpriteId]);
if (sImageTable_BrokenReelTimeMachine != NULL)
FREE_AND_SET_NULL(sImageTable_BrokenReelTimeMachine);
TRY_FREE_AND_SET_NULL(sImageTable_BrokenReelTimeMachine);
}
#define sDelayTimer data[0]

View File

@ -2160,8 +2160,7 @@ static bool32 IsDisplaySubtask0Active(void)
static void FreeDisplay(void)
{
FreeSprites();
if (sDisplay)
FREE_AND_SET_NULL(sDisplay);
TRY_FREE_AND_SET_NULL(sDisplay);
FreeAllWindowBuffers();
gScanlineEffect.state = 3;