From d8a71b513b9d219249a266c0c914a9c44e5b7e1f Mon Sep 17 00:00:00 2001 From: Tom Grobbe <31419184+TomGrobbe@users.noreply.github.com> Date: Thu, 21 May 2020 13:31:39 +0200 Subject: [PATCH] Add null checks and debug logs for issue #28 --- MenuAPI/MenuController.cs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/MenuAPI/MenuController.cs b/MenuAPI/MenuController.cs index d35e777..bfcb4da 100644 --- a/MenuAPI/MenuController.cs +++ b/MenuAPI/MenuController.cs @@ -241,10 +241,22 @@ private static void UnloadAssets() #if REDM menuTextureAssets.ForEach(asset => { - if (Call(HAS_STREAMED_TEXTURE_DICT_LOADED, asset)) + if (!string.IsNullOrEmpty(asset)) { - Call(SET_STREAMED_TEXTURE_DICT_AS_NO_LONGER_NEEDED, asset); + if (Call(HAS_STREAMED_TEXTURE_DICT_LOADED, asset)) + { +#if DEBUG + Debug.WriteLine($"[DEBUG] [{GetCurrentResourceName()}] [MenuAPI] Attempting to set asset as no longer needed: {asset}"); +#endif + Call(SET_STREAMED_TEXTURE_DICT_AS_NO_LONGER_NEEDED, asset); + } } +#if DEBUG + else + { + Debug.WriteLine($"[WARNING] [{GetCurrentResourceName()}] [MenuAPI] a menu asset is null somehow, can't set it as no longer needed."); + } +#endif }); #endif } @@ -528,7 +540,15 @@ private async Task ProcessToggleMenuButton() Call(DISABLE_CONTROL_ACTION, 0, MenuToggleKey, true); if (!Call(IS_PAUSE_MENU_ACTIVE) && Call(IS_SCREEN_FADED_IN) && !IsAnyMenuOpen() && !DisableMenuButtons && !Call(IS_ENTITY_DEAD, PlayerPedId()) && Call(IS_DISABLED_CONTROL_JUST_RELEASED, 0, MenuToggleKey)) { - MainMenu.OpenMenu(); + if (MainMenu != null) + { + MainMenu.OpenMenu(); + } + else + { + 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!"); + } + } #endif await Task.FromResult(0);