add "disable for this session" button to ImGui asserts

This commit is contained in:
goat 2024-12-25 17:03:22 +01:00
parent 12bf2f4478
commit 9d8bcb7a24
2 changed files with 15 additions and 9 deletions

View file

@ -8,7 +8,7 @@ using Dalamud.Utility;
using Serilog; using Serilog;
namespace Dalamud.Interface.Internal; namespace Dalamud.Interface.Internal.Asserts;
/// <summary> /// <summary>
/// Class responsible for registering and handling ImGui asserts. /// Class responsible for registering and handling ImGui asserts.
@ -36,7 +36,7 @@ internal class AssertHandler : IDisposable
/// <summary> /// <summary>
/// Gets or sets a value indicating whether ImGui asserts should be shown to the user. /// Gets or sets a value indicating whether ImGui asserts should be shown to the user.
/// </summary> /// </summary>
public bool ShowAsserts { get; set; } = false; public bool ShowAsserts { get; set; }
/// <summary> /// <summary>
/// Register the cimgui assert handler with the native library. /// Register the cimgui assert handler with the native library.
@ -93,7 +93,7 @@ internal class AssertHandler : IDisposable
var gitHubUrl = GetRepoUrl(); var gitHubUrl = GetRepoUrl();
var showOnGitHubButton = new TaskDialogButton var showOnGitHubButton = new TaskDialogButton
{ {
Text = "Show on GitHub", Text = "Open GitHub",
AllowCloseDialog = false, AllowCloseDialog = false,
Enabled = !gitHubUrl.IsNullOrEmpty(), Enabled = !gitHubUrl.IsNullOrEmpty(),
}; };
@ -108,9 +108,14 @@ internal class AssertHandler : IDisposable
Text = "Break", Text = "Break",
AllowCloseDialog = true, AllowCloseDialog = true,
}; };
var disableButton = new TaskDialogButton
{
Text = "Disable for this session",
AllowCloseDialog = true,
};
var ignoreButton = TaskDialogButton.Ignore; var ignoreButton = TaskDialogButton.Ignore;
var abortButton = TaskDialogButton.Abort;
TaskDialogButton? result = null; TaskDialogButton? result = null;
void DialogThreadStart() void DialogThreadStart()
@ -119,7 +124,7 @@ internal class AssertHandler : IDisposable
// this session since it already loaded visual styles... // this session since it already loaded visual styles...
Application.EnableVisualStyles(); Application.EnableVisualStyles();
var page = new TaskDialogPage() var page = new TaskDialogPage
{ {
Heading = "ImGui assertion failed", Heading = "ImGui assertion failed",
Caption = "Dalamud", Caption = "Dalamud",
@ -135,8 +140,8 @@ internal class AssertHandler : IDisposable
[ [
showOnGitHubButton, showOnGitHubButton,
breakButton, breakButton,
disableButton,
ignoreButton, ignoreButton,
abortButton,
], ],
DefaultButton = showOnGitHubButton, DefaultButton = showOnGitHubButton,
}; };
@ -157,9 +162,9 @@ internal class AssertHandler : IDisposable
{ {
Debugger.Break(); Debugger.Break();
} }
else if (result == abortButton) else if (result == disableButton)
{ {
Environment.Exit(-1); this.ShowAsserts = false;
} }
else if (result == ignoreButton) else if (result == ignoreButton)
{ {
@ -171,7 +176,7 @@ internal class AssertHandler : IDisposable
{ {
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)] [DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
#pragma warning disable SA1300 #pragma warning disable SA1300
public static extern void igCustom_SetAssertCallback(AssertCallbackDelegate callback); public static extern void igCustom_SetAssertCallback(AssertCallbackDelegate? callback);
#pragma warning restore SA1300 #pragma warning restore SA1300
} }
} }

View file

@ -19,6 +19,7 @@ using Dalamud.Hooking.Internal;
using Dalamud.Hooking.WndProcHook; using Dalamud.Hooking.WndProcHook;
using Dalamud.Interface.ImGuiNotification; using Dalamud.Interface.ImGuiNotification;
using Dalamud.Interface.ImGuiNotification.Internal; using Dalamud.Interface.ImGuiNotification.Internal;
using Dalamud.Interface.Internal.Asserts;
using Dalamud.Interface.Internal.DesignSystem; using Dalamud.Interface.Internal.DesignSystem;
using Dalamud.Interface.Internal.ReShadeHandling; using Dalamud.Interface.Internal.ReShadeHandling;
using Dalamud.Interface.ManagedFontAtlas; using Dalamud.Interface.ManagedFontAtlas;