From 719bdc7176ccaff0de944f5af681767d6ab02bad Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 24 Feb 2020 00:42:01 +0100 Subject: [PATCH] make MLEM.Ui not crash on DesktopGL.Core --- MLEM/Extensions/WindowExtensions.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/MLEM/Extensions/WindowExtensions.cs b/MLEM/Extensions/WindowExtensions.cs index 3db813e..3016cf5 100644 --- a/MLEM/Extensions/WindowExtensions.cs +++ b/MLEM/Extensions/WindowExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Reflection; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; @@ -13,7 +14,15 @@ namespace MLEM.Extensions { } public static bool SupportsTextInput() { - return TextInput != null; + if (TextInput == null) + return false; + // The newest version of DesktopGL.Core made a change where TextInputEventArgs doesn't extend EventArgs + // anymore, making this reflection system incompatible with it. For now, this just disables text input + // meaning that MLEM.Ui text boxes won't work, but at least it won't crash either. + // Let's hope there'll be one last update to DesktopGL that also introduces this change so we can fix this. + if (!typeof(EventArgs).IsAssignableFrom(TextInput.EventHandlerType.GenericTypeArguments.FirstOrDefault())) + return false; + return true; } public delegate void TextInputCallback(object sender, Keys key, char character); @@ -30,7 +39,7 @@ namespace MLEM.Extensions { } public bool AddToWindow(GameWindow window) { - if (TextInput == null) + if (!SupportsTextInput()) return false; TextInput.AddEventHandler(window, Delegate.CreateDelegate(TextInput.EventHandlerType, this, Callback)); return true;