Skip to content

Commit d8a71b5

Browse files
committed
Add null checks and debug logs for issue #28
1 parent d18dff7 commit d8a71b5

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

MenuAPI/MenuController.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,22 @@ private static void UnloadAssets()
241241
#if REDM
242242
menuTextureAssets.ForEach(asset =>
243243
{
244-
if (Call<bool>(HAS_STREAMED_TEXTURE_DICT_LOADED, asset))
244+
if (!string.IsNullOrEmpty(asset))
245245
{
246-
Call(SET_STREAMED_TEXTURE_DICT_AS_NO_LONGER_NEEDED, asset);
246+
if (Call<bool>(HAS_STREAMED_TEXTURE_DICT_LOADED, asset))
247+
{
248+
#if DEBUG
249+
Debug.WriteLine($"[DEBUG] [{GetCurrentResourceName()}] [MenuAPI] Attempting to set asset as no longer needed: {asset}");
250+
#endif
251+
Call(SET_STREAMED_TEXTURE_DICT_AS_NO_LONGER_NEEDED, asset);
252+
}
247253
}
254+
#if DEBUG
255+
else
256+
{
257+
Debug.WriteLine($"[WARNING] [{GetCurrentResourceName()}] [MenuAPI] a menu asset is null somehow, can't set it as no longer needed.");
258+
}
259+
#endif
248260
});
249261
#endif
250262
}
@@ -528,7 +540,15 @@ private async Task ProcessToggleMenuButton()
528540
Call(DISABLE_CONTROL_ACTION, 0, MenuToggleKey, true);
529541
if (!Call<bool>(IS_PAUSE_MENU_ACTIVE) && Call<bool>(IS_SCREEN_FADED_IN) && !IsAnyMenuOpen() && !DisableMenuButtons && !Call<bool>(IS_ENTITY_DEAD, PlayerPedId()) && Call<bool>(IS_DISABLED_CONTROL_JUST_RELEASED, 0, MenuToggleKey))
530542
{
531-
MainMenu.OpenMenu();
543+
if (MainMenu != null)
544+
{
545+
MainMenu.OpenMenu();
546+
}
547+
else
548+
{
549+
Debug.WriteLine($"[ERROR] [{GetCurrentResourceName()}] [MenuAPI] MainMenu is null, so we can't open it! Make sure that MenuController.MainMenu is set to a valid Menu which is not null!");
550+
}
551+
532552
}
533553
#endif
534554
await Task.FromResult(0);

0 commit comments

Comments
 (0)