Possible fix for lua crash #5269
Check if this instance has been disposed and don't call 'tick' if it has. Also remove the finalizer that was broken and wrong anyway. 'runtime' would never become null because it's readonly and managed resources are freed automatically or may have already been freed by then.
This commit is contained in:
@@ -21,7 +21,7 @@ namespace OpenRA.Mods.RA.Scripting
|
||||
[Desc("Allows map scripts to attach triggers to this actor via the Triggers global.")]
|
||||
public class ScriptTriggersInfo : TraitInfo<ScriptTriggers> { }
|
||||
|
||||
public class ScriptTriggers : INotifyIdle, INotifyDamage, INotifyKilled, INotifyProduction
|
||||
public class ScriptTriggers : INotifyIdle, INotifyDamage, INotifyKilled, INotifyProduction, IDisposable
|
||||
{
|
||||
public event Action<Actor> OnKilledInternal = _ => {};
|
||||
|
||||
@@ -101,21 +101,36 @@ namespace OpenRA.Mods.RA.Scripting
|
||||
}
|
||||
|
||||
bool disposed;
|
||||
|
||||
protected void Dispose(bool disposing)
|
||||
{
|
||||
if (disposed)
|
||||
return;
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
var toDispose = new [] { onIdle, onDamaged, onKilled, onProduction };
|
||||
|
||||
foreach (var f in toDispose.SelectMany(f => f))
|
||||
f.First.Dispose();
|
||||
|
||||
foreach (var l in toDispose)
|
||||
l.Clear();
|
||||
}
|
||||
|
||||
disposed = true;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
disposed = true;
|
||||
var toDispose = new [] { onIdle, onDamaged, onKilled, onProduction };
|
||||
|
||||
foreach (var f in toDispose.SelectMany(f => f))
|
||||
f.First.Dispose();
|
||||
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
~ScriptTriggers()
|
||||
{
|
||||
if (!disposed)
|
||||
Game.RunAfterTick(Dispose);
|
||||
// Dispose unmanaged resources only
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user