Skip to content

Commit

Permalink
fix: Forcefully load stacktrace if assert UI is shown (#2164)
Browse files Browse the repository at this point in the history
- Add DiagnosticUtil to automatically filter out the "boring" stack entries.

Co-authored-by: goat <16760685+goaaats@users.noreply.github.com>
  • Loading branch information
KazWolfe and goaaats authored Jan 9, 2025
1 parent a656fef commit bed591d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Dalamud/Interface/Internal/Asserts/AssertHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private void OnImGuiAssert(string expr, string file, int line)
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)
{
Expand Down Expand Up @@ -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
{
Expand Down
32 changes: 32 additions & 0 deletions Dalamud/Utility/DiagnosticUtil.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit bed591d

Please sign in to comment.