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.
67 lines
1.2 KiB
C#
67 lines
1.2 KiB
C#
#region Copyright & License Information
|
|
/*
|
|
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
|
|
* This file is part of OpenRA, which is free software. It is made
|
|
* available to you under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation. For more information,
|
|
* see COPYING.
|
|
*/
|
|
#endregion
|
|
|
|
using System;
|
|
using Eluant;
|
|
using OpenRA.Scripting;
|
|
using OpenRA.Traits;
|
|
|
|
namespace OpenRA.Mods.RA.Activities
|
|
{
|
|
public class CallLuaFunc : Activity, IDisposable
|
|
{
|
|
LuaFunction function;
|
|
|
|
public CallLuaFunc(LuaFunction func)
|
|
{
|
|
function = (LuaFunction)func.CopyReference();
|
|
}
|
|
|
|
public override Activity Tick(Actor self)
|
|
{
|
|
if (function != null)
|
|
function.Call().Dispose();
|
|
|
|
Dispose();
|
|
return NextActivity;
|
|
}
|
|
|
|
public override void Cancel(Actor self)
|
|
{
|
|
Dispose();
|
|
base.Cancel(self);
|
|
}
|
|
|
|
protected void Dispose(bool disposing)
|
|
{
|
|
if (function == null)
|
|
return;
|
|
|
|
if (disposing)
|
|
{
|
|
function.Dispose();
|
|
function = null;
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Dispose(true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
~CallLuaFunc()
|
|
{
|
|
// Dispose unmanaged resources only
|
|
Dispose(false);
|
|
}
|
|
}
|
|
}
|