22/*****************************************************************************
33 * The MIT License (MIT)
44 *
5- * Copyright (c) 2016-2018 MOARdV
5+ * Copyright (c) 2016-2022 MOARdV
66 *
77 * Permission is hereby granted, free of charge, to any person obtaining a copy
88 * of this software and associated documentation files (the "Software"), to
@@ -338,6 +338,17 @@ internal void SolveOrbitIntercept(Orbit vesselOrbit, Orbit targetOrbit)
338338 {
339339 now = vessel . StartUT ;
340340 then = vessel . EndUT ;
341+
342+ if ( double . IsInfinity ( then ) )
343+ {
344+ // If we get bogus values for 'then', it means we're probably not solving this -
345+ // maybe the orbit intercepts another body.
346+ targetClosestUT = vesselOrbit . StartUT ;
347+ targetClosestDistance = ( vesselOrbit . getPositionAtUT ( targetClosestUT ) - targetOrbit . getPositionAtUT ( targetClosestUT ) ) . magnitude ;
348+ targetClosestSpeed = ( vesselOrbit . GetFrameVelAtUT ( vesselOrbit . StartUT ) - targetOrbit . GetFrameVelAtUT ( vesselOrbit . StartUT ) ) . magnitude ;
349+
350+ return ;
351+ }
341352
342353 target1 = FindOrbit ( targetOrbit , vessel . StartUT ) ;
343354 target2 = FindOrbit ( targetOrbit , vessel . EndUT ) ;
@@ -360,6 +371,16 @@ internal void SolveOrbitIntercept(Orbit vesselOrbit, Orbit targetOrbit)
360371 // Final transition.
361372 now = vessel . StartUT ;
362373 then = vessel . EndUT ;
374+ if ( double . IsInfinity ( then ) )
375+ {
376+ // If we get bogus values for 'then', it means we're probably not solving this -
377+ // maybe the orbit intercepts another body.
378+ targetClosestUT = vesselOrbit . StartUT ;
379+ targetClosestDistance = ( vesselOrbit . getPositionAtUT ( targetClosestUT ) - targetOrbit . getPositionAtUT ( targetClosestUT ) ) . magnitude ;
380+ targetClosestSpeed = ( vesselOrbit . GetFrameVelAtUT ( vesselOrbit . StartUT ) - targetOrbit . GetFrameVelAtUT ( vesselOrbit . StartUT ) ) . magnitude ;
381+
382+ return ;
383+ }
363384
364385 // Don't bother searching ahead with hyperbolic orbits
365386 int orbitsToCheck = ( vessel . eccentricity < 1.0 ) ? NumOrbitsLookAhead : 1 ;
0 commit comments