mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-21 23:37:44 +01:00
pm: make sure to always destroy scope and interface when unloading a plugin
This commit is contained in:
parent
979f78a8b6
commit
8553ef5412
1 changed files with 28 additions and 16 deletions
|
|
@ -483,6 +483,7 @@ internal class LocalPlugin : IDisposable
|
||||||
{
|
{
|
||||||
case PluginState.Unloaded:
|
case PluginState.Unloaded:
|
||||||
throw new InvalidPluginOperationException($"Unable to unload {this.Name}, already unloaded");
|
throw new InvalidPluginOperationException($"Unable to unload {this.Name}, already unloaded");
|
||||||
|
case PluginState.DependencyResolutionFailed:
|
||||||
case PluginState.UnloadError:
|
case PluginState.UnloadError:
|
||||||
if (!this.IsDev)
|
if (!this.IsDev)
|
||||||
{
|
{
|
||||||
|
|
@ -501,31 +502,42 @@ internal class LocalPlugin : IDisposable
|
||||||
}
|
}
|
||||||
|
|
||||||
this.State = PluginState.Unloading;
|
this.State = PluginState.Unloading;
|
||||||
Log.Information($"Unloading {this.DllFile.Name}");
|
Log.Information("Unloading {PluginName}", this.InternalName);
|
||||||
|
|
||||||
if (this.manifest.CanUnloadAsync || framework == null)
|
try
|
||||||
this.instance?.Dispose();
|
|
||||||
else
|
|
||||||
await framework.RunOnFrameworkThread(() => this.instance?.Dispose());
|
|
||||||
|
|
||||||
this.instance = null;
|
|
||||||
this.UnloadAndDisposeState();
|
|
||||||
|
|
||||||
if (!reloading)
|
|
||||||
{
|
{
|
||||||
if (waitBeforeLoaderDispose && this.loader != null)
|
if (this.manifest.CanUnloadAsync || framework == null)
|
||||||
await Task.Delay(configuration.PluginWaitBeforeFree ?? PluginManager.PluginWaitBeforeFreeDefault);
|
this.instance?.Dispose();
|
||||||
this.loader?.Dispose();
|
else
|
||||||
this.loader = null;
|
await framework.RunOnFrameworkThread(() => this.instance?.Dispose());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
this.State = PluginState.UnloadError;
|
||||||
|
Log.Error(e, "Could not unload {PluginName}, error in plugin dispose", this.InternalName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
this.instance = null;
|
||||||
|
this.UnloadAndDisposeState();
|
||||||
|
|
||||||
|
if (!reloading)
|
||||||
|
{
|
||||||
|
if (waitBeforeLoaderDispose && this.loader != null)
|
||||||
|
await Task.Delay(configuration.PluginWaitBeforeFree ?? PluginManager.PluginWaitBeforeFreeDefault);
|
||||||
|
this.loader?.Dispose();
|
||||||
|
this.loader = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.State = PluginState.Unloaded;
|
this.State = PluginState.Unloaded;
|
||||||
Log.Information($"Finished unloading {this.DllFile.Name}");
|
Log.Information("Finished unloading {PluginName}", this.InternalName);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
this.State = PluginState.UnloadError;
|
this.State = PluginState.UnloadError;
|
||||||
Log.Error(ex, $"Error while unloading {this.Name}");
|
Log.Error(ex, "Error while unloading {PluginName}", this.InternalName);
|
||||||
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue