fix: Forcefully load stacktrace if assert UI is shown (#2164)

- Add DiagnosticUtil to automatically filter out the "boring" stack entries.

Co-authored-by: goat <16760685+goaaats@users.noreply.github.com>
This commit is contained in:
KazWolfe 2025-01-09 13:11:41 -08:00 committed by GitHub
parent a656fefb2b
commit bed591d890
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 1 deletions

View file

@ -82,7 +82,7 @@ internal class AssertHandler : IDisposable
if (!this.ShowAsserts && !this.everShownAssertThisSession)
return;
Lazy<string> stackTrace = new(() => new StackTrace(3).ToString());
Lazy<string> stackTrace = new(() => DiagnosticUtil.GetUsefulTrace(new StackTrace()).ToString());
if (!this.EnableVerboseLogging)
{
@ -133,6 +133,9 @@ internal class AssertHandler : IDisposable
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
{

View file

@ -0,0 +1,32 @@
using System.Diagnostics;
using System.Linq;
namespace Dalamud.Utility;
/// <summary>
/// A set of utilities for diagnostics.
/// </summary>
public static class DiagnosticUtil
{
private static readonly string[] IgnoredNamespaces = [
nameof(System),
nameof(ImGuiNET.ImGuiNative)
];
/// <summary>
/// Gets a stack trace that filters out irrelevant frames.
/// </summary>
/// <param name="source">The source stacktrace to filter.</param>
/// <returns>Returns a stack trace with "extra" frames removed.</returns>
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);
}
}