From 9d8bcb7a24148a33f2a8d182d73a4baf243e91a1 Mon Sep 17 00:00:00 2001 From: goat Date: Wed, 25 Dec 2024 17:03:22 +0100 Subject: [PATCH] add "disable for this session" button to ImGui asserts --- .../Internal/{ => Asserts}/AssertHandler.cs | 23 +++++++++++-------- .../Interface/Internal/InterfaceManager.cs | 1 + 2 files changed, 15 insertions(+), 9 deletions(-) rename Dalamud/Interface/Internal/{ => Asserts}/AssertHandler.cs (91%) diff --git a/Dalamud/Interface/Internal/AssertHandler.cs b/Dalamud/Interface/Internal/Asserts/AssertHandler.cs similarity index 91% rename from Dalamud/Interface/Internal/AssertHandler.cs rename to Dalamud/Interface/Internal/Asserts/AssertHandler.cs index 22aa75b9e..b0cfb462c 100644 --- a/Dalamud/Interface/Internal/AssertHandler.cs +++ b/Dalamud/Interface/Internal/Asserts/AssertHandler.cs @@ -8,7 +8,7 @@ using Dalamud.Utility; using Serilog; -namespace Dalamud.Interface.Internal; +namespace Dalamud.Interface.Internal.Asserts; /// /// Class responsible for registering and handling ImGui asserts. @@ -36,7 +36,7 @@ internal class AssertHandler : IDisposable /// /// Gets or sets a value indicating whether ImGui asserts should be shown to the user. /// - public bool ShowAsserts { get; set; } = false; + public bool ShowAsserts { get; set; } /// /// Register the cimgui assert handler with the native library. @@ -93,7 +93,7 @@ internal class AssertHandler : IDisposable var gitHubUrl = GetRepoUrl(); var showOnGitHubButton = new TaskDialogButton { - Text = "Show on GitHub", + Text = "Open GitHub", AllowCloseDialog = false, Enabled = !gitHubUrl.IsNullOrEmpty(), }; @@ -108,9 +108,14 @@ internal class AssertHandler : IDisposable Text = "Break", AllowCloseDialog = true, }; + + var disableButton = new TaskDialogButton + { + Text = "Disable for this session", + AllowCloseDialog = true, + }; var ignoreButton = TaskDialogButton.Ignore; - var abortButton = TaskDialogButton.Abort; TaskDialogButton? result = null; void DialogThreadStart() @@ -119,7 +124,7 @@ internal class AssertHandler : IDisposable // this session since it already loaded visual styles... Application.EnableVisualStyles(); - var page = new TaskDialogPage() + var page = new TaskDialogPage { Heading = "ImGui assertion failed", Caption = "Dalamud", @@ -135,8 +140,8 @@ internal class AssertHandler : IDisposable [ showOnGitHubButton, breakButton, + disableButton, ignoreButton, - abortButton, ], DefaultButton = showOnGitHubButton, }; @@ -157,9 +162,9 @@ internal class AssertHandler : IDisposable { Debugger.Break(); } - else if (result == abortButton) + else if (result == disableButton) { - Environment.Exit(-1); + this.ShowAsserts = false; } else if (result == ignoreButton) { @@ -171,7 +176,7 @@ internal class AssertHandler : IDisposable { [DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)] #pragma warning disable SA1300 - public static extern void igCustom_SetAssertCallback(AssertCallbackDelegate callback); + public static extern void igCustom_SetAssertCallback(AssertCallbackDelegate? callback); #pragma warning restore SA1300 } } diff --git a/Dalamud/Interface/Internal/InterfaceManager.cs b/Dalamud/Interface/Internal/InterfaceManager.cs index af9f61647..36f48f9b8 100644 --- a/Dalamud/Interface/Internal/InterfaceManager.cs +++ b/Dalamud/Interface/Internal/InterfaceManager.cs @@ -19,6 +19,7 @@ using Dalamud.Hooking.Internal; using Dalamud.Hooking.WndProcHook; using Dalamud.Interface.ImGuiNotification; using Dalamud.Interface.ImGuiNotification.Internal; +using Dalamud.Interface.Internal.Asserts; using Dalamud.Interface.Internal.DesignSystem; using Dalamud.Interface.Internal.ReShadeHandling; using Dalamud.Interface.ManagedFontAtlas;