post-kerbin-mining-corporation / SpaceDust

Adds atmospheric and exoatmospheric resource discovery and extraction to Kerbal Space Program.
9 stars 12 forks source link

NRE if focusing on a maneuver node. #51

Closed neitsa closed 2 months ago

neitsa commented 1 year ago

Hi Chris,

I also have a mod called "Precise Maneuver". This mod has a neat feature which lets you focus on a maneuver node (especially useful if the view is focused on a moon / planet and the maneuver node is far away from it).

image

It seems that if focusing on a node, multiple NRE originate from SpaceDust in SpaceDust.ToolbarUI.OnMapFocusChange

NRE # 1:

[PlanetariumCamera]: Focus: Maneuver #1 
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 35)

[SpaceDust][ToolbarUI] Changed focus to Maneuver #1 
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 35)

Exception handling event OnMapFocusChange in class ToolbarUI:System.NullReferenceException: Object reference not set to an instance of an object
  at SpaceDust.ToolbarUI.OnMapFocusChange (MapObject mapObject) [0x00035] in <cb9e8fd1f4744849900ab173326b539f>:0 
  at EventData`1[T].Fire (T data) [0x000b0] in <4b449f2841f84227adfaad3149c8fdba>:0  
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 35)

Uploading Crash Report
NullReferenceException: Object reference not set to an instance of an object
  at SpaceDust.ToolbarUI.OnMapFocusChange (MapObject mapObject) [0x00035] in <cb9e8fd1f4744849900ab173326b539f>:0 
  at EventData`1[T].Fire (T data) [0x000b0] in <4b449f2841f84227adfaad3149c8fdba>:0 
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
KSPe.Util.Log.UnityLogDecorator:UnityEngine.ILogHandler.LogException(Exception, Object)
ModuleManager.UnityLogHandle.InterceptLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
EventData`1:Fire(MapObject)
PlanetariumCamera:SetTarget(MapObject)
KSPPreciseManeuver.PagerControlInterface:FocusButtonPressed()
KSPPreciseManeuver.UI.PagerControl:FocusButtonAction()
UnityEngine.Events.InvokableCall:Invoke()
UnityEngine.Events.UnityEvent:Invoke()
UnityEngine.UI.Button:Press()
UnityEngine.UI.Button:OnPointerClick(PointerEventData)
UnityEngine.EventSystems.ExecuteEvents:Execute(IPointerClickHandler, BaseEventData)
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
UnityEngine.EventSystems.StandaloneInputModule:ReleaseMouse(PointerEventData, GameObject)
UnityEngine.EventSystems.StandaloneInputModule:ProcessMousePress(MouseButtonEventData)
UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent(Int32)
UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent()
UnityEngine.EventSystems.StandaloneInputModule:Process()
UnityEngine.EventSystems.EventSystem:Update()

(Filename: <cb9e8fd1f4744849900ab173326b539f> Line: 0)

NRE # 2:

[PlanetariumCamera]: Focus: Maneuver #1 
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 35)

[SpaceDust][ToolbarUI] Changed focus to Maneuver #1 
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 35)

Exception handling event OnMapFocusChange in class ToolbarUI:System.NullReferenceException: Object reference not set to an instance of an object
  at SpaceDust.ToolbarUI.OnMapFocusChange (MapObject mapObject) [0x00035] in <cb9e8fd1f4744849900ab173326b539f>:0 
  at EventData`1[T].Fire (T data) [0x000b0] in <4b449f2841f84227adfaad3149c8fdba>:0  
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 35)

Uploading Crash Report
NullReferenceException: Object reference not set to an instance of an object
  at SpaceDust.ToolbarUI.OnMapFocusChange (MapObject mapObject) [0x00035] in <cb9e8fd1f4744849900ab173326b539f>:0 
  at EventData`1[T].Fire (T data) [0x000b0] in <4b449f2841f84227adfaad3149c8fdba>:0 
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
KSPe.Util.Log.UnityLogDecorator:UnityEngine.ILogHandler.LogException(Exception, Object)
ModuleManager.UnityLogHandle.InterceptLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
EventData`1:Fire(MapObject)
PlanetariumCamera:SetTarget(MapObject)
PlanetariumCamera:SetTarget(Int32)
MapView:MapView.enterMapView_Patch1(MapView)
MapView:EnterMapView()
MapView:Update()

This function code is quite small and with 2 null checks already:

https://github.com/post-kerbin-mining-corporation/SpaceDust/blob/a5d59da55d7a9cd0dce1d34ac2937673950f5637/Source/SpaceDust/Overlay/ToolbarUI.cs#L66-L80

So, since the mapObject is a maneuver node, I'm guessing that mapObject.vessel may be null in this case?

https://github.com/post-kerbin-mining-corporation/SpaceDust/blob/a5d59da55d7a9cd0dce1d34ac2937673950f5637/Source/SpaceDust/Overlay/ToolbarUI.cs#L76

Let me know if you need more details.

Thanks a lot for reading this issue and for your mods!

ChrisAdderley commented 2 months ago

Fix released