MOARdV / AvionicsSystems

MOARdV's Avionics Systems for Kerbal Space Program - a new generation of IVA enhancement.
Other
52 stars 26 forks source link

Infinite loop in ApproachSolver #332

Closed sovetskysoyuz closed 2 years ago

sovetskysoyuz commented 3 years ago

I have a recurring issue with an infinite loop causing KSP to hang.

The issue occurs when trying to make a transfer burn from LKO to Minmus. If the transfer orbit path intersects the Mun's SOI, I get an endless stream of these messages in my log (300,000 lines in 15 seconds!): [LOG 02:46:33.178] getObtAtUT infinite UT on elliptical orbit UT: Infinity, returning NaN

at System.Environment.get_StackTrace () [0x00000] in <ad04dee02e7e4a85a1299c7ee81c79f6>:0

at Orbit.getObtAtUT (System.Double UT) [0x00000] in <2afc64dea36946459d4707808bdac511>:0

at Orbit.getPositionAtUT (System.Double UT) [0x00000] in <2afc64dea36946459d4707808bdac511>:0

at AvionicsSystems.ApproachSolver.FindClosest (Orbit sourceOrbit, Orbit targetOrbit, System.Double startUT, System.Double endUT, System.Int32 recursionDepth, System.Double& closestDistance, System.Double& closestUT) [0x00000] in <a9ccaf957f8644eda33ca47259aeb04c>:0

at AvionicsSystems.ApproachSolver.SolveOrbitIntercept (Orbit vesselOrbit, Orbit targetOrbit) [0x00000] in <a9ccaf957f8644eda33ca47259aeb04c>:0

at AvionicsSystems.ApproachSolver.SolveBodyIntercept (Orbit vesselOrbit, CelestialBody targetBody) [0x00000] in <a9ccaf957f8644eda33ca47259aeb04c>:0

at AvionicsSystems.MASVesselComputer.get_targetClosestUT () [0x00000] in <a9ccaf957f8644eda33ca47259aeb04c>:0

at AvionicsSystems.MASFlightComputerProxy.TargetClosestApproachTime () [0x00000] in <a9ccaf957f8644eda33ca47259aeb04c>:0

at AvionicsSystems.DynamicMethodFactory. (System.Object ) [0x00000] in <a9ccaf957f8644eda33ca47259aeb04c>:0

at AvionicsSystems.MASFlightComputer+<>c__DisplayClass69_2.<Generate0ParmCallVariable>b__1 () [0x00000] in <a9ccaf957f8644eda33ca47259aeb04c>:0

at AvionicsSystems.DoubleVariable.Evaluate (System.Boolean invokeCallbacks) [0x00000] in <a9ccaf957f8644eda33ca47259aeb04c>:0

at AvionicsSystems.MASFlightComputer.FixedUpdate () [0x00000] in <a9ccaf957f8644eda33ca47259aeb04c>:0

I rebuilt the DLL with some extra logging in SolveOrbitIntercept() and found that, immediately before the first such error, the variable then (set equal to vessel.EndUT) had become infinite; presumably this value, when passed to findClosest() and onward to getObtAtUT(), is the issue.

I'm not sure what conditions cause EndUT() to return an infinite value, but the sequence of UT values in my log suggest that it's looking at the conic patch representing a solar orbit, since entering the Mun's SOI means that at that moment the projected orbit after the Mun's gravity assist will escape the Kerbin SOI.

[LOG 02:46:33.176] [ApproachSolver] ApproachSolver second FindClosest: vessel Orbit, target1 Orbit, now 9443914.41589554, then 9464702.14981331, closestDistance3.40282346638529E+38, closestUT0 - 5.75 hours is consistent with the time to reach the Mun from Kerbin.

[LOG 02:46:33.176] [ApproachSolver] ApproachSolver second FindClosest: vessel Orbit, target1 Orbit, now 9464702.14981331, then 9477171.14609312, closestDistance40907697.1005853, closestUT9459892.82941436 - 3.5 hours is consistent with the time to complete a hyperbolic flypast of the Mun.

[LOG 02:46:33.176] [ApproachSolver] ApproachSolver second FindClosest: vessel Orbit, target1 Orbit, now 9477171.14609312, then 9604948.95315318, closestDistance33774120.5613578, closestUT9477171.14609311 - presumably this is the cruise to reach the edge of the Kerbin SOI.

[LOG 02:46:33.176] [ApproachSolver] ApproachSolver second FindClosest: vessel Orbit, target1 Orbit, now 9604948.95315318, then Infinity, closestDistance33774120.5613578, closestUT9477171.14609311 - the last line before the errors start.