mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
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:
parent
a656fefb2b
commit
bed591d890
2 changed files with 36 additions and 1 deletions
|
|
@ -82,7 +82,7 @@ internal class AssertHandler : IDisposable
|
||||||
if (!this.ShowAsserts && !this.everShownAssertThisSession)
|
if (!this.ShowAsserts && !this.everShownAssertThisSession)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Lazy<string> stackTrace = new(() => new StackTrace(3).ToString());
|
Lazy<string> stackTrace = new(() => DiagnosticUtil.GetUsefulTrace(new StackTrace()).ToString());
|
||||||
|
|
||||||
if (!this.EnableVerboseLogging)
|
if (!this.EnableVerboseLogging)
|
||||||
{
|
{
|
||||||
|
|
@ -133,6 +133,9 @@ internal class AssertHandler : IDisposable
|
||||||
return $"https://github.com/{userName}/{repoName}/blob/{branch}/{fileName}#L{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 gitHubUrl = GetRepoUrl();
|
||||||
var showOnGitHubButton = new TaskDialogButton
|
var showOnGitHubButton = new TaskDialogButton
|
||||||
{
|
{
|
||||||
|
|
|
||||||
32
Dalamud/Utility/DiagnosticUtil.cs
Normal file
32
Dalamud/Utility/DiagnosticUtil.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue