mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-21 07:59:18 +01:00
feat: Identify the plugin causing an assertion failure
This commit is contained in:
parent
2affbe3683
commit
32cb6e2127
1 changed files with 41 additions and 19 deletions
|
|
@ -4,6 +4,7 @@ using System.Runtime.InteropServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
using Dalamud.Plugin.Internal;
|
||||||
using Dalamud.Utility;
|
using Dalamud.Utility;
|
||||||
|
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
@ -55,7 +56,8 @@ internal class AssertHandler : IDisposable
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public unsafe void Setup()
|
public unsafe void Setup()
|
||||||
{
|
{
|
||||||
CustomNativeFunctions.igCustom_SetAssertCallback(Marshal.GetFunctionPointerForDelegate(this.callback).ToPointer());
|
CustomNativeFunctions.igCustom_SetAssertCallback(
|
||||||
|
Marshal.GetFunctionPointerForDelegate(this.callback).ToPointer());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -78,10 +80,11 @@ internal class AssertHandler : IDisposable
|
||||||
var file = Marshal.PtrToStringAnsi(new IntPtr(pFile));
|
var file = Marshal.PtrToStringAnsi(new IntPtr(pFile));
|
||||||
if (expr == null || file == null)
|
if (expr == null || file == null)
|
||||||
{
|
{
|
||||||
Log.Warning("ImGui assertion failed: {Expr} at {File}:{Line} (failed to parse)",
|
Log.Warning(
|
||||||
expr,
|
"ImGui assertion failed: {Expr} at {File}:{Line} (failed to parse)",
|
||||||
file,
|
expr,
|
||||||
line);
|
file,
|
||||||
|
line);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,7 +96,7 @@ internal class AssertHandler : IDisposable
|
||||||
if (!this.ShowAsserts && !this.everShownAssertThisSession)
|
if (!this.ShowAsserts && !this.everShownAssertThisSession)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Lazy<string> stackTrace = new(() => DiagnosticUtil.GetUsefulTrace(new StackTrace()).ToString());
|
Lazy<StackTrace> stackTrace = new(() => DiagnosticUtil.GetUsefulTrace(new StackTrace()));
|
||||||
|
|
||||||
if (!this.EnableVerboseLogging)
|
if (!this.EnableVerboseLogging)
|
||||||
{
|
{
|
||||||
|
|
@ -103,11 +106,12 @@ internal class AssertHandler : IDisposable
|
||||||
|
|
||||||
if (count <= HideThreshold || count % HidePrintEvery == 0)
|
if (count <= HideThreshold || count % HidePrintEvery == 0)
|
||||||
{
|
{
|
||||||
Log.Warning("ImGui assertion failed: {Expr} at {File}:{Line} (repeated {Count} times)",
|
Log.Warning(
|
||||||
expr,
|
"ImGui assertion failed: {Expr} at {File}:{Line} (repeated {Count} times)",
|
||||||
file,
|
expr,
|
||||||
line,
|
file,
|
||||||
count);
|
line,
|
||||||
|
count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -117,11 +121,12 @@ internal class AssertHandler : IDisposable
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log.Warning("ImGui assertion failed: {Expr} at {File}:{Line}\n{StackTrace:l}",
|
Log.Warning(
|
||||||
expr,
|
"ImGui assertion failed: {Expr} at {File}:{Line}\n{StackTrace:l}",
|
||||||
file,
|
expr,
|
||||||
line,
|
file,
|
||||||
stackTrace.Value);
|
line,
|
||||||
|
stackTrace.Value.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.ShowAsserts)
|
if (!this.ShowAsserts)
|
||||||
|
|
@ -145,7 +150,7 @@ internal class AssertHandler : IDisposable
|
||||||
}
|
}
|
||||||
|
|
||||||
// grab the stack trace now that we've decided to show UI.
|
// grab the stack trace now that we've decided to show UI.
|
||||||
_ = stackTrace.Value;
|
var responsiblePlugin = Service<PluginManager>.GetNullable()?.FindCallingPlugin(stackTrace.Value);
|
||||||
|
|
||||||
var gitHubUrl = GetRepoUrl();
|
var gitHubUrl = GetRepoUrl();
|
||||||
var showOnGitHubButton = new TaskDialogButton
|
var showOnGitHubButton = new TaskDialogButton
|
||||||
|
|
@ -175,12 +180,29 @@ internal class AssertHandler : IDisposable
|
||||||
var ignoreButton = TaskDialogButton.Ignore;
|
var ignoreButton = TaskDialogButton.Ignore;
|
||||||
|
|
||||||
TaskDialogButton? result = null;
|
TaskDialogButton? result = null;
|
||||||
|
|
||||||
void DialogThreadStart()
|
void DialogThreadStart()
|
||||||
{
|
{
|
||||||
// TODO(goat): This is probably not gonna work if we showed the loading dialog
|
// TODO(goat): This is probably not gonna work if we showed the loading dialog
|
||||||
// this session since it already loaded visual styles...
|
// this session since it already loaded visual styles...
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
|
|
||||||
|
string text;
|
||||||
|
if (responsiblePlugin != null)
|
||||||
|
{
|
||||||
|
text = $"The plugin \"{responsiblePlugin.Name}\" appears to have caused an ImGui assertion failure. " +
|
||||||
|
$"Please report this problem to the plugin's developer.\n\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
text = "Some code in a plugin or Dalamud itself has caused an ImGui assertion failure. " +
|
||||||
|
"Please report this problem in the Dalamud discord.\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
text += $"You may attempt to continue running the game, but Dalamud UI elements may not work " +
|
||||||
|
$"correctly, or the game may crash after resuming.\n\n" +
|
||||||
|
$"{expr}\nAt: {file}:{line}";
|
||||||
|
|
||||||
var page = new TaskDialogPage
|
var page = new TaskDialogPage
|
||||||
{
|
{
|
||||||
Heading = "ImGui assertion failed",
|
Heading = "ImGui assertion failed",
|
||||||
|
|
@ -189,9 +211,9 @@ internal class AssertHandler : IDisposable
|
||||||
{
|
{
|
||||||
CollapsedButtonText = "Show stack trace",
|
CollapsedButtonText = "Show stack trace",
|
||||||
ExpandedButtonText = "Hide stack trace",
|
ExpandedButtonText = "Hide stack trace",
|
||||||
Text = stackTrace.Value,
|
Text = stackTrace.Value.ToString(),
|
||||||
},
|
},
|
||||||
Text = $"Some code in a plugin or Dalamud itself has caused an internal assertion in ImGui to fail. The game will most likely crash now.\n\n{expr}\nAt: {file}:{line}",
|
Text = text,
|
||||||
Icon = TaskDialogIcon.Warning,
|
Icon = TaskDialogIcon.Warning,
|
||||||
Buttons =
|
Buttons =
|
||||||
[
|
[
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue