post-kerbin-mining-corporation/DynamicBatteryStorage

NRE in onPartRemove handler after reverting from flight

Closed this issue · 3 comments

Launching, reverting back to the VAB, and removing a part from the vessel triggers an exception in DynamicBatteryStorage version 2.0.1:

[ERR 22:14:49.616] Exception handling event onPartRemove in class EditorVesselDataManager:System.NullReferenceException: Object reference not set to an instance of an object
  at DynamicBatteryStorage.EditorVesselDataManager.RemovePart (.Part p) [0x00000] in <filename unknown>:0 
  at DynamicBatteryStorage.EditorVesselDataManager.onEditorVesselPartRemoved (HostTargetAction`2 p) [0x00000] in <filename unknown>:0 
  at EventData`1[GameEvents+HostTargetAction`2[Part,Part]].Fire (HostTargetAction`2 data) [0x00000] in <filename unknown>:0 

[EXC 22:14:49.804] NullReferenceException: Object reference not set to an instance of an object
        DynamicBatteryStorage.EditorVesselDataManager.RemovePart (.Part p)
        DynamicBatteryStorage.EditorVesselDataManager.onEditorVesselPartRemoved (HostTargetAction`2 p)
        EventData`1[GameEvents+HostTargetAction`2[Part,Part]].Fire (HostTargetAction`2 data)
        UnityEngine.Debug:LogException(Exception)
        EventData`1:Fire(HostTargetAction`2)
        Part:setParent(Part)
        EditorLogic:detachPart(Part)
        EditorLogic:<SetupFSM>m__1F()
        KerbalFSM:RunEvent(KFSMEvent)
        KerbalFSM:updateFSM(KFSMUpdateMode)
        KerbalFSM:UpdateFSM()
        EditorLogic:Update()

I've reproduced this in a new sandbox save in KSP 1.7.3 (on Linux, though I doubt that matters) with no mods besides DynamicBatteryStorage. Test vessel was a Stayputnik, FL-T200 fuel tank, and Terrier engine, with a launch clamp attached to the fuel tank. After going to the launchpad and then doing "revert to vehicle assembly", removing the engine triggered the exception above.

I've actually fixed this in the current development version (it looks like that with a revert versus a pure load there is a 2 frame delay in loading certain VAB components).

Good to know. I didn't see the posts about NREs in the forum thread until after I submitted this, but the circumstances there seemed to be different (switching vessels in flight, as opposed to reverting to VAB) so I figured this might be a separate bug.

Yep this is a different case (third one). I discovered it also when I was testing the fixes for the other two.