KSP-KOS / KOS

Fully programmable autopilot mod for KSP. Originally By Nivekk
Other
691 stars 229 forks source link

Wrong function called and stack misalignment #1668

Closed dewiniaid closed 7 years ago

dewiniaid commented 8 years ago

I'm having issues slimming down my test case (which spans several files), so here is a gist with the affected.

When running lib_orbit_tests from the attached gist, KOS throws an error about stack misalignment. There's two different triggers depending on whether the orbital eccentricity is greater than 1 or not -- the e>1 case triggers at the end of a function that shouldn't have even been called.

e<=1 case:

kOS internal error: Stack misalignment detected when returning from routine.
At lib_util.ks on archive, line 46
FUNCTION _acosh { PARAMETER x. PRINT "in acosh!". x. RETURN K_DEGREES*LN(x+SQRT(x^2-1)). }
                                                                      ^
Called from lib_orbit.ks on archive, line 119
SET m TO eacos((e+COS(m))/(1+e*COS(m))).
                           ^
Called from lib_orbit.ks on archive, line 50
LOCAL mna IS orb_convert_anomaly(obt:trueanomaly,obt:eccentricity,KA_TRUE,KA_MEAN).
                                                                           ^
Called from lib_orbit_tests on archive, line 8
LOCAL o IS orb_from_orbit().

e>1 case:

kOS internal error: Stack misalignment detected when returning from routine.
At lib_util.ks on archive, line 46
FUNCTION _acosh { PARAMETER x. PRINT "in acosh!". x. RETURN K_DEGREES*LN(x+SQRT(x^2-1)). }
                                                                      ^
Called from lib_orbit.ks on archive, line 230
LOCAL ta IS ACOSE(evec*r/(evec:mag*r:mag),mult).  // True anomaly
                                           ^
Called from lib_orbit_tests on archive, line 57
LOCAL o IS orb_set_time(orb_from_vectors(RELPOSITION(obt), obt:velocity:orbit),t).

It's worth noting there's a lot of use of delegates being used here -- both to builtin functions (arcsin/etc) and KerboScript functions. In fact, most of the delegates use :bind(another_delegate@) in their construction.

Note that nowhere in the logical flow in the second stack trace should _acosh have ever even been entered -- yet it is called (evidenced by the debugging PRINT triggering.)

hvacengi commented 8 years ago

@Dunbaratu mentioned in slack the other day that he thinks there is a misalignment happening somewhere but he wasn't sure where. Perhaps this example will help him find the problem.

Is there any chance you could run this with the error and pass along the full log file?

For the time being I'm going to add this to the v1.0.0 milestone, but it will depend on if we can find the issue in time for release.

dewiniaid commented 8 years ago

It's been awhile, but I'll see if I can repro. Fortunately it's all still in the gist.

dewiniaid commented 8 years ago

Okay, apparently somehow the gist has a different version of lib_util (and, indeed, everything else) than the one I could swear I uploaded. I'll see if I can figure out what the actual version I had was at the time.

Dunbaratu commented 7 years ago

Should we finally close this issue? It's only open because we were waiting to see if it could still be reproduced. It's been 9 months without that happening.

Dunbaratu commented 7 years ago

Due to the difficulty of re-creating the problem, and due to the fact that this has been waiting in limbo for 9 months to see if @dewiniaid could re-create it, with no movement during that time. We're going to close it.

If you want to re-discuss the issue, feel free to open a new issue with new information for it.