Merge pull request #6704 from chrisforbes/closure-hazards

Closure hazards -- Fixes #6703
This commit is contained in:
obrakmann
2014-10-07 20:01:19 +02:00
6 changed files with 20 additions and 9 deletions

View File

@@ -86,14 +86,17 @@ namespace OpenRA.Editor
// TODO: make this work properly // TODO: make this work properly
foreach (var init in Program.Rules.Actors[kv.Value.Type].GetInitKeys()) foreach (var init in Program.Rules.Actors[kv.Value.Type].GetInitKeys())
apd.AddRow(init.First, {
var initName = init.First;
apd.AddRow(initName,
apd.MakeEditorControl(init.Second, apd.MakeEditorControl(init.Second,
() => () =>
{ {
var nodesDict = objSaved.ToDictionary(); var nodesDict = objSaved.ToDictionary();
return nodesDict.ContainsKey(init.First) ? nodesDict[init.First].Value : null; return nodesDict.ContainsKey(initName) ? nodesDict[initName].Value : null;
}, },
_ => { })); _ => { }));
}
apd.ShowDialog(); apd.ShowDialog();

View File

@@ -199,13 +199,14 @@ namespace OpenRA.FileSystem
foreach (var ext in exts) foreach (var ext in exts)
{ {
var possibleName = filename + ext;
var folder = MountedFolders var folder = MountedFolders
.Where(x => x.Exists(filename + ext)) .Where(x => x.Exists(possibleName))
.MaxByOrDefault(x => x.Priority); .MaxByOrDefault(x => x.Priority);
if (folder != null) if (folder != null)
{ {
s = folder.GetContent(filename + ext); s = folder.GetContent(possibleName);
return true; return true;
} }
} }

View File

@@ -68,9 +68,10 @@ namespace OpenRA.Mods.RA
foreach (var actor in inRange.Append(collector)) foreach (var actor in inRange.Append(collector))
{ {
actor.World.AddFrameEndTask(w => var recipient = actor; // loop variable in closure hazard
recipient.World.AddFrameEndTask(w =>
{ {
var gainsExperience = actor.TraitOrDefault<GainsExperience>(); var gainsExperience = recipient.TraitOrDefault<GainsExperience>();
if (gainsExperience != null) if (gainsExperience != null)
gainsExperience.GiveLevels(((LevelUpCrateActionInfo)info).Levels); gainsExperience.GiveLevels(((LevelUpCrateActionInfo)info).Levels);
}); });

View File

@@ -67,13 +67,16 @@ namespace OpenRA.Mods.RA
// TODO: THIS IS SHIT // TODO: THIS IS SHIT
// Cancel existing primaries // Cancel existing primaries
foreach (var p in self.Info.Traits.Get<ProductionInfo>().Produces) foreach (var p in self.Info.Traits.Get<ProductionInfo>().Produces)
{
var productionType = p; // benign closure hazard
foreach (var b in self.World foreach (var b in self.World
.ActorsWithTrait<PrimaryBuilding>() .ActorsWithTrait<PrimaryBuilding>()
.Where(a => .Where(a =>
a.Actor.Owner == self.Owner && a.Actor.Owner == self.Owner &&
a.Trait.IsPrimary && a.Trait.IsPrimary &&
a.Actor.Info.Traits.Get<ProductionInfo>().Produces.Contains(p))) a.Actor.Info.Traits.Get<ProductionInfo>().Produces.Contains(productionType)))
b.Trait.SetPrimaryProducer(b.Actor, false); b.Trait.SetPrimaryProducer(b.Actor, false);
}
isPrimary = true; isPrimary = true;

View File

@@ -38,6 +38,8 @@ namespace OpenRA.Mods.RA.Render
foreach (var arm in self.TraitsImplementing<Armament>()) foreach (var arm in self.TraitsImplementing<Armament>())
{ {
var armClosure = arm; // closure hazard in AnimationWithOffset
// Skip armaments that don't define muzzles // Skip armaments that don't define muzzles
if (arm.Info.MuzzleSequence == null) if (arm.Info.MuzzleSequence == null)
continue; continue;
@@ -55,7 +57,7 @@ namespace OpenRA.Mods.RA.Render
visible.Add(barrel, false); visible.Add(barrel, false);
anims.Add(barrel, anims.Add(barrel,
new AnimationWithOffset(muzzleFlash, new AnimationWithOffset(muzzleFlash,
() => info.IgnoreOffset ? WVec.Zero : arm.MuzzleOffset(self, barrel), () => info.IgnoreOffset ? WVec.Zero : armClosure.MuzzleOffset(self, barrel),
() => !visible[barrel], () => !visible[barrel],
() => false, () => false,
p => WithTurret.ZOffsetFromCenter(self, p, 2))); p => WithTurret.ZOffsetFromCenter(self, p, 2)));

View File

@@ -89,7 +89,8 @@ namespace OpenRA.Mods.RA
foreach (var cell in dirtyCells) foreach (var cell in dirtyCells)
{ {
// Select all neighbors inside the map boundries // Select all neighbors inside the map boundries
var neighbors = CVec.directions.Select(d => d + cell) var thisCell = cell; // benign closure hazard
var neighbors = CVec.directions.Select(d => d + thisCell)
.Where(c => map.Contains(c)); .Where(c => map.Contains(c));
var found = false; var found = false;