KSP-RO / TestFlight

KSP Mod that provides a part research and reliability system
42 stars 31 forks source link

Null reference spam if Testflight is disabled from the Space Center #273

Closed Nazfib closed 1 year ago

Nazfib commented 1 year ago

I have disabled TestFlight from the menu in the SpaceCenter (for a sandbox save). In flight, it spams the following exception to the log file:

Module TestFlightFailure_IgnitionFail threw during OnUpdate: System.NullReferenceException: Object reference not set to an instance of an object
  at TestFlight.TestFlightFailure_IgnitionFail.GetIgnitionChance (System.Single& currentIgnitionChance, System.Single& maxIgnitionChance) [0x0001f] in <0d8c8881b9e64bf18046f4a49c522b6f>:0 
  at TestFlight.TestFlightFailure_IgnitionFail.SetActiveConfig (System.String alias) [0x0019f] in <0d8c8881b9e64bf18046f4a49c522b6f>:0 
  at TestFlightCore.TestFlightCore.UpdatePartConfig () [0x000b6] in <37798846d5ec4d90a6315949b8f99083>:0 
  at TestFlightAPI.TestFlightUtil.GetCore (Part part, System.String alias) [0x00025] in <46f8a9b4eed445bba3f50ffc505c589e>:0 
  at TestFlight.TestFlightFailure_Engine.get_TestFlightEnabled () [0x0002f] in <0d8c8881b9e64bf18046f4a49c522b6f>:0 
  at TestFlight.TestFlightFailure_IgnitionFail.OnUpdate () [0x00000] in <0d8c8881b9e64bf18046f4a49c522b6f>:0 
  at Part.ModulesOnUpdate () [0x0004a] in <4deecb19beb547f19b1ff89b4c59bd84>:0  

If I enable TF in the SpaceCenter and then disable it on the launch pad, no exception spam occurs.

I suspect the issue is caused by #263: when TestFlight is disabled, GetCore will always return null https://github.com/KSP-RO/TestFlight/blob/8d345e5012e15cec8d7e67e5cf35676a2da46e24/TestFlightAPI/TestFlightAPI/TestFlightAPI.cs#L285-L295 which will then cause a NRE later in GetIgnitionChance.

siimav commented 1 year ago

I think I saw something similar at one point but when I asked someone else if it happens for them as well, the answer was no. So I just shrugged it off to my janky dev install.

CC: @Falki-git