Skip to content

Commit

Permalink
Fix ModularLaunchPads
Browse files Browse the repository at this point in the history
The important fix is the null check in HasDeactivatedEngineOrTankDescendant.

That was throwing.  Null does not have a deactivated engine or tank
descendant.

Yet another billion dollar bug.

Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed May 10, 2021
1 parent e9e0b6d commit 04d576e
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions MechJeb2/MechJebModuleStagingController.cs
Expand Up @@ -381,11 +381,8 @@ public static bool InverseStageFiresDecoupler(int inverseStage, Vessel v)
for (int i = 0; i < v.parts.Count; i++)
{
Part p = v.parts[i];
Part decoupled;
if (p.inverseStage == inverseStage && p.IsUnfiredDecoupler(out decoupled))
{
if (p.inverseStage == inverseStage && p.IsUnfiredDecoupler(out Part decoupled))
return true;
}
}
return false;
}
Expand All @@ -410,18 +407,18 @@ public static bool InverseStageDecouplesDeactivatedEngineOrTank(int inverseStage
for (int i = 0; i < v.parts.Count; i++)
{
Part p = v.parts[i];
Part decoupledPart;
if (p.inverseStage == inverseStage && p.IsUnfiredDecoupler(out decoupledPart) && HasDeactivatedEngineOrTankDescendant(decoupledPart))
{
if (p.inverseStage == inverseStage && p.IsUnfiredDecoupler(out Part decoupledPart) && HasDeactivatedEngineOrTankDescendant(decoupledPart))
return true;
}
}
return false;
}

//detect if a part is above a deactivated engine or fuel tank
public static bool HasDeactivatedEngineOrTankDescendant(Part p)
{
if (p is null)
return false;

if ((p.State == PartStates.DEACTIVATED) && (p.IsEngine()) && !p.IsSepratron())
{
return true; // TODO: yet more ModuleEngine lazy checks
Expand All @@ -444,9 +441,7 @@ public static bool HasDeactivatedEngineOrTankDescendant(Part p)
for (int i = 0; i < p.children.Count; i++)
{
if (HasDeactivatedEngineOrTankDescendant(p.children[i]))
{
return true;
}
}
return false;
}
Expand Down

0 comments on commit 04d576e

Please sign in to comment.