From dcf6221671aa6d68cc989b6d0cd896a10fb35dc6 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Fri, 23 Aug 2024 22:48:53 -0400 Subject: [PATCH] error check and more verbose error log --- MiraAPI/Hud/CustomButtonManager.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/MiraAPI/Hud/CustomButtonManager.cs b/MiraAPI/Hud/CustomButtonManager.cs index 2b09d7b..e3adae5 100644 --- a/MiraAPI/Hud/CustomButtonManager.cs +++ b/MiraAPI/Hud/CustomButtonManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Reflection; +using Reactor.Utilities; namespace MiraAPI.Hud; @@ -12,10 +13,16 @@ public static class CustomButtonManager { if (!typeof(CustomActionButton).IsAssignableFrom(buttonType)) { + Logger.Error($"{buttonType?.Name} does not inherit from CustomActionButton."); return; } - var button = (CustomActionButton)Activator.CreateInstance(buttonType); + if (Activator.CreateInstance(buttonType) is not CustomActionButton button) + { + Logger.Error($"Failed to create button from {buttonType.Name}"); + return; + } + CustomButtons.Add(button); typeof(CustomButtonSingleton<>).MakeGenericType(buttonType) .GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)!