diff --git a/Dalamud/Interface/Internal/Asserts/AssertHandler.cs b/Dalamud/Interface/Internal/Asserts/AssertHandler.cs index 376aaed5b..56050cdfb 100644 --- a/Dalamud/Interface/Internal/Asserts/AssertHandler.cs +++ b/Dalamud/Interface/Internal/Asserts/AssertHandler.cs @@ -82,7 +82,7 @@ private void OnImGuiAssert(string expr, string file, int line) if (!this.ShowAsserts && !this.everShownAssertThisSession) return; - Lazy stackTrace = new(() => new StackTrace(3).ToString()); + Lazy stackTrace = new(() => DiagnosticUtil.GetUsefulTrace(new StackTrace()).ToString()); if (!this.EnableVerboseLogging) { @@ -133,6 +133,9 @@ private void OnImGuiAssert(string expr, string file, int line) return $"https://github.com/{userName}/{repoName}/blob/{branch}/{fileName}#L{line}"; } + // grab the stack trace now that we've decided to show UI. + _ = stackTrace.Value; + var gitHubUrl = GetRepoUrl(); var showOnGitHubButton = new TaskDialogButton { diff --git a/Dalamud/Utility/DiagnosticUtil.cs b/Dalamud/Utility/DiagnosticUtil.cs new file mode 100644 index 000000000..9c9718c4e --- /dev/null +++ b/Dalamud/Utility/DiagnosticUtil.cs @@ -0,0 +1,32 @@ +using System.Diagnostics; +using System.Linq; + +namespace Dalamud.Utility; + +/// +/// A set of utilities for diagnostics. +/// +public static class DiagnosticUtil +{ + private static readonly string[] IgnoredNamespaces = [ + nameof(System), + nameof(ImGuiNET.ImGuiNative) + ]; + + /// + /// Gets a stack trace that filters out irrelevant frames. + /// + /// The source stacktrace to filter. + /// Returns a stack trace with "extra" frames removed. + public static StackTrace GetUsefulTrace(StackTrace source) + { + var frames = source.GetFrames().SkipWhile( + f => + { + var frameNs = f.GetMethod()?.DeclaringType?.Namespace; + return frameNs == null || IgnoredNamespaces.Any(i => frameNs.StartsWith(i, true, null)); + }); + + return new StackTrace(frames); + } +}