@@ -46,13 +46,22 @@ public override string Description
4646
4747 public override bool Pop ( FlightComputer f )
4848 {
49+ if ( f . Vessel . patchedConicSolver == null )
50+ {
51+ f . Vessel . AttachPatchedConicsSolver ( ) ;
52+ f . Vessel . patchedConicSolver . Update ( ) ;
53+ }
54+
4955 // check if the stored node is still valid
50- if ( f . Vessel . patchedConicSolver . maneuverNodes . IndexOf ( this . Node ) < 0 )
56+ if ( f . Vessel . patchedConicSolver . maneuverNodes . FindIndex ( x => x . UT == this . Node . UT && x . DeltaV == this . Node . DeltaV ) < 0 ) //IndexOf() is bad comparer
5157 {
5258 RTUtil . ScreenMessage ( "[Flight Computer]: No maneuver node found." ) ;
5359 return false ;
5460 }
5561
62+ if ( this . Node . solver == null ) // need to repair (due to the scenario of 2 vessels within phyical range)
63+ this . Node = f . Vessel . patchedConicSolver . maneuverNodes . Find ( x => x . UT == this . Node . UT && x . DeltaV == this . Node . DeltaV ) ;
64+
5665 var burn = f . ActiveCommands . FirstOrDefault ( c => c is BurnCommand ) ;
5766 if ( burn != null ) {
5867 f . Remove ( burn ) ;
@@ -92,7 +101,7 @@ private void AbortManeuver(FlightComputer computer)
92101 RTUtil . ScreenMessage ( "[Flight Computer]: Maneuver node removed" ) ;
93102 if ( computer . Vessel . patchedConicSolver != null )
94103 {
95- Node . RemoveSelf ( ) ;
104+ this . Node . RemoveSelf ( ) ;
96105 }
97106
98107 // Flight Computer mode after execution based on settings
@@ -246,13 +255,22 @@ public static ManeuverCommand WithNode(int nodeIndex, FlightComputer f)
246255 /// <returns>true - loaded successfull</returns>
247256 public override bool Load ( ConfigNode n , FlightComputer fc )
248257 {
258+ //Additional notes: Load() is never called when cold-launching KSP and resuming flight.
249259 if ( base . Load ( n , fc ) )
250260 {
251261 if ( n . HasValue ( "NodeIndex" ) )
252262 {
253263 this . NodeIndex = int . Parse ( n . GetValue ( "NodeIndex" ) ) ;
254- RTLog . Notify ( "Trying to get Maneuver {0}" , this . NodeIndex ) ;
255- if ( this . NodeIndex >= 0 )
264+
265+ if ( fc . Vessel . patchedConicSolver == null )
266+ {
267+ fc . Vessel . AttachPatchedConicsSolver ( ) ;
268+ fc . Vessel . patchedConicSolver . Update ( ) ;
269+ }
270+
271+ RTLog . Notify ( "Trying to get Maneuver {0} in the list of {1} maneuver nodes" , this . NodeIndex , fc . Vessel . patchedConicSolver . maneuverNodes . Count ) ;
272+
273+ if ( this . NodeIndex >= 0 && fc . Vessel . patchedConicSolver . maneuverNodes . Count > 0 )
256274 {
257275 // Set the ManeuverNode into this command
258276 this . Node = fc . Vessel . patchedConicSolver . maneuverNodes [ this . NodeIndex ] ;
@@ -271,8 +289,14 @@ public override bool Load(ConfigNode n, FlightComputer fc)
271289 /// </summary>
272290 public override void Save ( ConfigNode n , FlightComputer fc )
273291 {
292+ if ( fc . Vessel . patchedConicSolver == null )
293+ {
294+ fc . Vessel . AttachPatchedConicsSolver ( ) ;
295+ fc . Vessel . patchedConicSolver . Update ( ) ;
296+ }
297+
274298 // search the node on the List
275- this . NodeIndex = fc . Vessel . patchedConicSolver . maneuverNodes . IndexOf ( this . Node ) ;
299+ this . NodeIndex = fc . Vessel . patchedConicSolver . maneuverNodes . FindIndex ( x => x . UT == this . Node . UT && x . DeltaV == this . Node . DeltaV ) ;
276300
277301 // only save this command if we are on the maneuverNode list
278302 if ( this . NodeIndex >= 0 )
0 commit comments