Throw an exception if a reservation is eaten by the GC. Better to die early with a known error than to desync later.
This commit is contained in:
@@ -14,22 +14,27 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
public class DisposableAction : IDisposable
|
public class DisposableAction : IDisposable
|
||||||
{
|
{
|
||||||
public DisposableAction(Action a) { this.a = a; }
|
public DisposableAction(Action onDispose, Action onFinalize)
|
||||||
|
{
|
||||||
|
this.onDispose = onDispose;
|
||||||
|
this.onFinalize = onFinalize;
|
||||||
|
}
|
||||||
|
|
||||||
Action a;
|
Action onDispose;
|
||||||
|
Action onFinalize;
|
||||||
bool disposed;
|
bool disposed;
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
if (disposed) return;
|
if (disposed) return;
|
||||||
disposed = true;
|
disposed = true;
|
||||||
a();
|
onDispose();
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
~DisposableAction()
|
~DisposableAction()
|
||||||
{
|
{
|
||||||
Dispose();
|
onFinalize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,10 +32,10 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
reservedFor = forActor;
|
reservedFor = forActor;
|
||||||
|
|
||||||
return new DisposableAction(() =>
|
return new DisposableAction(() => { reservedFor = null; },
|
||||||
{
|
() => Game.RunAfterTick(() =>
|
||||||
reservedFor = null;
|
{throw new InvalidOperationException("Attempted to finalize an undisposed DisposableAction");})
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsReserved(Actor a)
|
public static bool IsReserved(Actor a)
|
||||||
|
|||||||
Reference in New Issue
Block a user