KSPModdingLibs / KSPCommunityFixes

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

New Patch: Fix Planetarium.GetUniversalTime() in editor #155

Closed NathanKell closed 1 year ago

NathanKell commented 1 year ago

GetUniversalTime is supposed to detect when it's invalid and return HighLogic.CurrentGame.UniversalTime but at some point Planetarium started running in the editor which means its check for fetch == null returns false, so it still tries to get UT from its instance. But the instance has the UT from before the last revert, rather than from the current game.

Fix: Make the check fetch == null || HighLogic.LoadedSceneIsEditor. RP-1 has used this check for a long time (with its own wrapper for GetUniversalTime) and it's been fine, but there's plenty of code--including stock code--that assumes GetUniversalTime is correct.

Brought to my attention by https://github.com/KSP-RO/RP-1/issues/2067 (because StrategySystem's Update runs in the editor, because of course it does).

NathanKell commented 1 year ago

Update: Gonna ship this patch in RP-1 and let it bake for a week or two before making it in KSPCF. @gotmachine can do it as a transpiler when he has time, I'm just gonna prefix.

https://github.com/KSP-RO/RP-1/commit/b8ef7ba526d789b1c7d0267bc84c4cccd7e20fb2

NathanKell commented 1 year ago

Fixed in https://github.com/KSPModdingLibs/KSPCommunityFixes/commit/e756eb203074c2fa09ac19729f46e715db83b922