Fix TOCTOU issues when calling Game.RunAfterDelay.
Since the action runs after a delay, the state of the game may no longer be the same and it may no longer be valid to run the action. Anything that references the world now calls IsCurrentWorld to ensure the world hasn't changed or been disposed.
This commit is contained in:
@@ -62,22 +62,22 @@ namespace OpenRA.Mods.Common.Traits
|
||||
foreach (var a in player.World.Actors.Where(a => a.Owner == player))
|
||||
a.Kill(a);
|
||||
|
||||
if (player == player.World.LocalPlayer)
|
||||
Game.RunAfterDelay(info.NotificationDelay, () =>
|
||||
{
|
||||
Game.RunAfterDelay(info.NotificationDelay, () =>
|
||||
{
|
||||
if (Game.IsCurrentWorld(player.World))
|
||||
Game.Sound.PlayNotification(player.World.Map.Rules, player, "Speech", "Lose", player.Faction.InternalName);
|
||||
});
|
||||
}
|
||||
if (Game.IsCurrentWorld(player.World) && player == player.World.LocalPlayer)
|
||||
Game.Sound.PlayNotification(player.World.Map.Rules, player, "Speech", "Lose", player.Faction.InternalName);
|
||||
});
|
||||
}
|
||||
|
||||
public void OnPlayerWon(Player player)
|
||||
{
|
||||
Game.Debug("{0} is victorious.", player.PlayerName);
|
||||
|
||||
if (player == player.World.LocalPlayer)
|
||||
Game.RunAfterDelay(info.NotificationDelay, () => Game.Sound.PlayNotification(player.World.Map.Rules, player, "Speech", "Win", player.Faction.InternalName));
|
||||
Game.RunAfterDelay(info.NotificationDelay, () =>
|
||||
{
|
||||
if (Game.IsCurrentWorld(player.World) && player == player.World.LocalPlayer)
|
||||
Game.Sound.PlayNotification(player.World.Map.Rules, player, "Speech", "Win", player.Faction.InternalName);
|
||||
});
|
||||
}
|
||||
|
||||
public void OnObjectiveAdded(Player player, int id) { }
|
||||
|
||||
Reference in New Issue
Block a user