fix: unload plugins before unloading Dalamud to prevent crashes

This commit is contained in:
Liam 2021-04-23 22:20:11 -04:00
parent de98b75336
commit 581cb506cc
4 changed files with 52 additions and 23 deletions

View file

@ -351,6 +351,26 @@ namespace Dalamud
this.finishUnloadSignal?.WaitOne();
}
public void DisposePlugins()
{
// this must be done before unloading plugins, or it can cause a race condition
// due to rendering happening on another thread, where a plugin might receive
// a render call after it has been disposed, which can crash if it attempts to
// use any resources that it freed in its own Dispose method
this.InterfaceManager?.Dispose();
try
{
this.PluginManager.UnloadPlugins();
}
catch (Exception ex)
{
Log.Error(ex, "Plugin unload failed.");
}
this.DalamudUi?.Dispose();
}
/// <summary>
/// Dispose Dalamud subsystems.
/// </summary>
@ -358,27 +378,6 @@ namespace Dalamud
{
try
{
// this must be done before unloading plugins, to prevent crashes due to errors
// in plugin cleanup
this.Framework.DispatchUpdateEvents = false;
// this must be done before unloading plugins, or it can cause a race condition
// due to rendering happening on another thread, where a plugin might receive
// a render call after it has been disposed, which can crash if it attempts to
// use any resources that it freed in its own Dispose method
this.InterfaceManager?.Dispose();
try
{
this.PluginManager.UnloadPlugins();
}
catch (Exception ex)
{
Log.Error(ex, "Plugin unload failed.");
}
this.DalamudUi?.Dispose();
this.Framework?.Dispose();
this.ClientState?.Dispose();