KSPModdingLibs/KSPCommunityFixes

Jumping to high timewarp levels from off-rails will alter the active vessel's orbital elements

JonnyOThan opened this issue · 4 comments

https://www.reddit.com/r/KerbalSpaceProgram/comments/189fr5b/this_glitch_is_occurring_when_i_try_to_go_to_duna/

I've seen this happen so often that using 5x timewarp first is just muscle memory now. If we could fix this one it would be a huge benefit.

On the other hand, the workaround is not difficult. So either you learn the workaround or you learn to install KSPCF. I think the former is probably easier but it's the principle of the thing...

I guess this happened to me too, but not nearly often enough to identify why it was happening.
A reproducible setup or save would be helpful...

If I were to take a guess, I'd say this might have to do with the TimeWarp class wrongly assuming a 1:1 call ratio between the TimeWarp.autoWarpTo coroutine (which is yielding on FixedUpdate) and stuff happening in Update(). In the linked reddit video, the user in in "yellow" lag range, which means that he is likely having multiple FixedUpdate cycles back to back per Update cycle (which will get worse when the "max physics delta-time per frame" is set to higher values).

One way to verify such a theory in the presence of this bug would be to set Time.maximumDeltaTime = 0.02 and see if the bug still reproduce (unfortunately, it can be set lower than 0.03 in the KSP main menu settings, but doing so might still have an effect). If it doesn't, a quick and dirty workaround would be to force maximumDeltaTime for a few frames when the TimeWarp.autoWarpTo coroutine is spawned, but identifying the root cause would be nice, although in my experience fixing the root cause of such synchronization issues is difficult without triggering other side effects.

Edit : yep, can confirm this is the issue. I can reproduce it consistently by putting a 1500 part vessel in orbit while having the max dt per frame at 0.12, and engaging max timewarp speed.

Awesome. I'm not too familiar with the Timewarp system but the problem is not limited to "autoWarpTo" - which I think you confirmed? You can also trigger it by clicking the max warp button in the UI.

Yeah, I wrote that before testing, but this is reproducible no matter the method used to engage timewarp.

I need to do some proper debugging, but I suspect this won't be so easy to fix (just like with other similar KSP issues involving update/fixedupdate being wrongly assumed to be in prefect sync).

Fix included in 1.32.0