Open JonnyOThan opened 11 months ago
As all kOS does is call FlightGlobals.SetActiveVessel(vessel);
or FlightGlobals.ForceSetActiveVessel(vessel);
when you set those suffixes (code here) this sounds to me like KSP is doing something extra when you change vessel from within the IVA view that they really should have built into the methods.
While true, since ksp won’t be getting those fixes anymore it does seem like something kOS will have to check for
Chances are the stock KSP API never expected the UX to let a player switch scenes from inside IVA, so the problem it causes is never experienced in stock play.
There's a lot of these messy cases in KSP, where protections against Bad Things that really belong down in the API are only enforced by the UX code not providing the player with a button or keypress that would invoke the Bad Thing. (Thus why we ended up just banning NaN and Infinity in kOS mathematics because otherwise a player script can just take that NaN or Infinity and send it into a KSP API call that throws exception when it tries using the value.)
@Dunbaratu see the note on my comment. You CAN switch vessels from IVA in stock (use square bracket keys) and the bug does not occur. It’s specific to whatever KOS is doing. More likely, the stock code is doing some other bookkeeping inside the button press handler in addition to actually switching vessels.
Repro steps:
kuniverse:activevessel
orkuniverse:forceactive
Results: NREs are spewed:
This does NOT occur if you use square brackets to change vessels in step 3. I'm pretty sure the root issue here is that the InternalCamera.Instance object is a child object of the kerbal inside the IVA. Normally the camera would be detached when changing the active vessel, but somehow KOS is changing vessels without detaching the camera so it is destroyed along with the old IVA. The only way to fix it is a scene change.