CYBUTEK / KerbalEngineer

Kerbal Engineer v1.0 (current in-development build).
227 stars 101 forks source link

Infinite loop in CalcInterceptAngle / AngleHelper.Clamp360 #126

Closed jd284 closed 7 years ago

jd284 commented 7 years ago

This appears to be the cause of a long-standing issue with KerbalEngineer locking up the game when a ground base is targetted with the rendezvous window open.

It's extremely difficult to reproduce, happens for me every couple of weeks only. After adding a bunch of debug print statements I finally narrowed it down to an infinite loop in AngleHelper.Clamp360, which happens when it is called with an argument of Infinity by CalcInterceptAngle in the RendezvousProcessor. Of course adding or subtracting from infinity makes no difference whatsoever so the while loops never terminate.

So to fix it, a couple of solutions come to mind:

I haven't been able to reproduce the problem since narrowing it down, so I can't say yet exactly why the angle is infinite. I'll post more if I find out.

jd284 commented 7 years ago

Huh, just after I gave up on reproducing it, there it was again.

So it turns out that targetRadius is zero, hence the argument to Math.Pow has a division by zero.

FatHand commented 7 years ago

Can confirm experiencing this on Mac, KSP 1.2.2.

Orbiting Mun. No target selected. Opened Rendezvous window and began search for a Mun base. Clicked search result and the game froze.

Had recently passed over the base at about 20km altitude.

Just reproduced it with the same base and craft while in Kerbin SOI transferring to Mun.

CYBUTEK commented 7 years ago

The AngleHelper clamps now check for NaN and Infinity before processing in bde5d1d3c9e82bad50711b1319e5ba39f0a4c891, this should resolve the issue.