Ensure LuaValues are disposed.
Adding in these missing calls prevents these instances from having to be finalized.
This commit is contained in:
@@ -34,8 +34,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
[Desc("Call a function after a specified delay. The callback function will be called as func().")]
|
||||
public void AfterDelay(int delay, LuaFunction func)
|
||||
{
|
||||
var f = func.CopyReference() as LuaFunction;
|
||||
|
||||
var f = (LuaFunction)func.CopyReference();
|
||||
Action doCall = () =>
|
||||
{
|
||||
try
|
||||
@@ -78,17 +77,15 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
public void OnAllKilled(Actor[] actors, LuaFunction func)
|
||||
{
|
||||
var group = actors.ToList();
|
||||
var copy = (LuaFunction)func.CopyReference();
|
||||
var f = (LuaFunction)func.CopyReference();
|
||||
Action<Actor> onMemberKilled = m =>
|
||||
{
|
||||
try
|
||||
{
|
||||
group.Remove(m);
|
||||
if (!group.Any())
|
||||
{
|
||||
copy.Call();
|
||||
copy.Dispose();
|
||||
}
|
||||
using (f)
|
||||
f.Call();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -105,7 +102,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
public void OnAnyKilled(Actor[] actors, LuaFunction func)
|
||||
{
|
||||
var called = false;
|
||||
var copy = (LuaFunction)func.CopyReference();
|
||||
var f = (LuaFunction)func.CopyReference();
|
||||
Action<Actor> onMemberKilled = m =>
|
||||
{
|
||||
try
|
||||
@@ -113,10 +110,10 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
if (called)
|
||||
return;
|
||||
|
||||
using (f)
|
||||
using (var killed = m.ToLuaValue(Context))
|
||||
copy.Call(killed).Dispose();
|
||||
f.Call(killed).Dispose();
|
||||
|
||||
copy.Dispose();
|
||||
called = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -191,7 +188,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
var group = actors.ToList();
|
||||
|
||||
var copy = (LuaFunction)func.CopyReference();
|
||||
var f = (LuaFunction)func.CopyReference();
|
||||
Action<Actor> onMemberRemoved = m =>
|
||||
{
|
||||
try
|
||||
@@ -200,10 +197,8 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
return;
|
||||
|
||||
if (!group.Any())
|
||||
{
|
||||
copy.Call().Dispose();
|
||||
copy.Dispose();
|
||||
}
|
||||
using (f)
|
||||
f.Call().Dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -228,7 +223,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
var called = false;
|
||||
|
||||
var copy = (LuaFunction)func.CopyReference();
|
||||
var f = (LuaFunction)func.CopyReference();
|
||||
Action<Actor> onKilledOrCaptured = m =>
|
||||
{
|
||||
try
|
||||
@@ -236,8 +231,9 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
if (called)
|
||||
return;
|
||||
|
||||
copy.Call().Dispose();
|
||||
copy.Dispose();
|
||||
using (f)
|
||||
f.Call().Dispose();
|
||||
|
||||
called = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -256,7 +252,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
var group = actors.ToList();
|
||||
|
||||
var copy = (LuaFunction)func.CopyReference();
|
||||
var f = (LuaFunction)func.CopyReference();
|
||||
Action<Actor> onMemberKilledOrCaptured = m =>
|
||||
{
|
||||
try
|
||||
@@ -265,10 +261,8 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
return;
|
||||
|
||||
if (!group.Any())
|
||||
{
|
||||
copy.Call().Dispose();
|
||||
copy.Dispose();
|
||||
}
|
||||
using (f)
|
||||
f.Call().Dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -288,8 +282,9 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
"The callback function will be called as func(Actor a, int id).")]
|
||||
public int OnEnteredFootprint(CPos[] cells, LuaFunction func)
|
||||
{
|
||||
var triggerId = 0;
|
||||
// We can't easily dispose onEntry, so we'll have to rely on finalization for it.
|
||||
var onEntry = (LuaFunction)func.CopyReference();
|
||||
var triggerId = 0;
|
||||
Action<Actor> invokeEntry = a =>
|
||||
{
|
||||
try
|
||||
@@ -314,8 +309,9 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
"The callback function will be called as func(Actor a, int id).")]
|
||||
public int OnExitedFootprint(CPos[] cells, LuaFunction func)
|
||||
{
|
||||
var triggerId = 0;
|
||||
// We can't easily dispose onExit, so we'll have to rely on finalization for it.
|
||||
var onExit = (LuaFunction)func.CopyReference();
|
||||
var triggerId = 0;
|
||||
Action<Actor> invokeExit = a =>
|
||||
{
|
||||
try
|
||||
@@ -346,8 +342,9 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
"The callback function will be called as func(Actor a, int id).")]
|
||||
public int OnEnteredProximityTrigger(WPos pos, WDist range, LuaFunction func)
|
||||
{
|
||||
var triggerId = 0;
|
||||
// We can't easily dispose onEntry, so we'll have to rely on finalization for it.
|
||||
var onEntry = (LuaFunction)func.CopyReference();
|
||||
var triggerId = 0;
|
||||
Action<Actor> invokeEntry = a =>
|
||||
{
|
||||
try
|
||||
@@ -372,8 +369,9 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
"The callback function will be called as func(Actor a, int id).")]
|
||||
public int OnExitedProximityTrigger(WPos pos, WDist range, LuaFunction func)
|
||||
{
|
||||
var triggerId = 0;
|
||||
// We can't easily dispose onExit, so we'll have to rely on finalization for it.
|
||||
var onExit = (LuaFunction)func.CopyReference();
|
||||
var triggerId = 0;
|
||||
Action<Actor> invokeExit = a =>
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user