KSPModdingLibs / KSPCommunityFixes

Community patches for bugs in the KSP codebase
49 stars 17 forks source link

Action Group Brakes gets locked out if Time is moved backwards with Hyperedit. #240

Open HB-Stratos opened 1 month ago

HB-Stratos commented 1 month ago

Provide a description of the KSP bug or improvement I often use Hyperedit's Set Time feature to e.g. compare how a TUFX config looks at day and night, or to achieve a specific cloud pattern with EVE. However, if time is set backwards from current game time instead of forwards (e.g. setting time from 14,000 to 0) causes the brakes action group to become locked. The toggle button on screen becomes unclickable and pressing the action group hotkey also does not work. Only pressing the action group hotkey triggers a message in the log though: Cannot toggle Brakes. 16469.5 seconds until it becomes available again I am guessing some sort of rate-limiting code for the Brakes is responsible for this issue. I seem to remember this used to also be an issue with lights and gear, however those remain unaffected in ksp 1.12.5. Another possible explanation for the issue may be that brakes is an action group that requires the hotkey to be held down, it is momentary instead of toggle, which may have required some different handling in code. Personally I think this code should not even be present, I have never experienced a point in gameplay where quickly toggling brakes twice has caused any issues.

JonnyOThan commented 1 month ago

This isn't specific to brakes. All action groups store the last UTC where they were toggled and if it's in the future then you can't toggle it again. We ran into this in TPKSP when I tried to reset the universe clock due to floating point imprecision when it got too high.

Not really sure why the code works like that, but we'd need to understand it before fixing it.

gotmachine commented 1 month ago

I'd say that in general, trying to move time backward is likely to cause various issues, both in stock and in mods. Is this really worth a fix ?

JonnyOThan commented 1 month ago

If it looks safe, sure. I don’t recall any other symptoms after resetting the clock (though of course I can’t rule out problems in mods I wasn’t using).

HB-Stratos commented 1 month ago

I haven't seen any issues occur either. I don't use it for normal gameplay, it doesn't matter there, but for testing of configurations and mods that affect the environment, it's quite useful.

JonnyOThan commented 1 month ago

Yeah the bigger problem is that once UTC exceeds 1200 (stock) years or so, things start falling apart. It might be interesting to do something in KSPCF to address that more generally (sounds hard, but sure would be nice).

Resetting UTC is just one way to work around the problem, but the action group issue can really break vessels in flight and it seems like it should be easy to fix as long as there's no negative side effects.