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:
@@ -15,12 +15,13 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class CallLuaFunc : Activity
|
||||
public class CallLuaFunc : Activity, IDisposable
|
||||
{
|
||||
LuaFunction function;
|
||||
|
||||
public CallLuaFunc(LuaFunction func)
|
||||
{
|
||||
function = func.CopyReference() as LuaFunction;
|
||||
function = (LuaFunction)func.CopyReference();
|
||||
}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
@@ -38,20 +39,28 @@ namespace OpenRA.Mods.RA.Activities
|
||||
base.Cancel(self);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
protected void Dispose(bool disposing)
|
||||
{
|
||||
if (function == null)
|
||||
return;
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
function.Dispose();
|
||||
function = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
function.Dispose();
|
||||
function = null;
|
||||
}
|
||||
|
||||
~CallLuaFunc()
|
||||
{
|
||||
if (function != null)
|
||||
Game.RunAfterTick(Dispose);
|
||||
// Dispose unmanaged resources only
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user