Craxy / ToggleTrafficLights

Mod for Cities:Skylines. Tool to remove or add traffic lights at intersections.
Other
33 stars 10 forks source link

NullReferenceException when activating Junction Tool #41

Closed Craxy closed 7 years ago

Craxy commented 7 years ago

Reported by Boehrsi: (23 Jul @ 2:56pm and 24 Jul @ 9:18am in TTL Comments)

For me it's sadly still broken. The button is not clickable and CTRL+T triggers the street menu but it just activates the normal building mode, instead of toggling traffic lights.

Linked Stack Traces:

NullReferenceException: Object reference not set to an instance of an object
  at Craxy.CitiesSkylines.ToggleTrafficLights.Game.Behaviours.MainMachine.ActivateIntersectionTool (Boolean keepInfoMode, Elevation elevation) [0x00000] in <filename unknown>:0 
  at Craxy.CitiesSkylines.ToggleTrafficLights.Game.Behaviours.MainMachine.ActivateIntersectionTool (Boolean keepInfoMode) [0x00000] in <filename unknown>:0 
  at Craxy.CitiesSkylines.ToggleTrafficLights.Game.Behaviours.MainMachine.OnMessage (Message message) [0x00000] in <filename unknown>:0 
  at Craxy.CitiesSkylines.ToggleTrafficLights.Game.Behaviours.MainMachine.Send (Message message) [0x00000] in <filename unknown>:0 
  at Craxy.CitiesSkylines.ToggleTrafficLights.Game.Behaviours.MainMachine.HandleShortcut (UnityEngine.Event e, ColossalFramework.SavedInputKey shortcut, Message message) [0x00000] in <filename unknown>:0 
  at Craxy.CitiesSkylines.ToggleTrafficLights.Game.Behaviours.MainMachine.HandleShortcuts () [0x00000] in <filename unknown>:0 
  at Craxy.CitiesSkylines.ToggleTrafficLights.Game.Behaviours.MainMachine.OnGUI () [0x00000] in <filename unknown>:0 

(Filename: Line: -1)

(source: https://gist.github.com/anonymous/44bb2c31e8cece76b7201f23d2533123 )

NullReferenceException: Object reference not set to an instance of an object
  at Craxy.CitiesSkylines.ToggleTrafficLights.Game.Behaviours.MainMachine.ActivateIntersectionTool (Boolean keepInfoMode, Elevation elevation) [0x00000] in <filename unknown>:0 
  at Craxy.CitiesSkylines.ToggleTrafficLights.Game.Behaviours.MainMachine.OnMessage (Message message) [0x00000] in <filename unknown>:0 
  at Craxy.CitiesSkylines.ToggleTrafficLights.Game.Behaviours.MainMachine.Send (Message message) [0x00000] in <filename unknown>:0 
  at Craxy.CitiesSkylines.ToggleTrafficLights.Game.Behaviours.ToggleTrafficLightsButton.OnButtonClick (ColossalFramework.UI.UIComponent _, ColossalFramework.UI.UIMouseEventParameter e) [0x00000] in <filename unknown>:0 
  at ColossalFramework.UI.UIComponent.OnClick (ColossalFramework.UI.UIMouseEventParameter p) [0x00000] in <filename unknown>:0 
  at ColossalFramework.UI.UIButton.OnClick (ColossalFramework.UI.UIMouseEventParameter p) [0x00000] in <filename unknown>:0 
  at ColossalFramework.UI.UIInput+MouseHandler.ProcessInput (IInputTranslator translator, Ray ray, ColossalFramework.UI.UIComponent component, Boolean retainFocusSetting) [0x00000] in <filename unknown>:0 
  at ColossalFramework.UI.UIInput.ProcessMouseInput () [0x00000] in <filename unknown>:0 
  at ColossalFramework.UI.UIInput.Update () [0x00000] in <filename unknown>:0 

(Filename: Line: -1)

(source: https://gist.github.com/anonymous/027a64a62ddf8e66440b4a870949c623 )

Issue is: ActivateAndReturnTool<JunctionTool>() returns null (and in the function: ToolsModifierControl.SetTool<T>() returns null). Therefore tool.CurrentElevation throws a NullReferenceException. That happens when JunctionTool isn't in ToolsModifierControl.m_Tools. JunctionTool is added in MainMachine.Awake()->Setup()->SetupTool(). Therefore JunctionTool should be in ToolsModifierControl.m_Tools -- but isn't for Boehrsi.

Two ideas why that might be the case:

Craxy commented 7 years ago

Further logging from Boehrsi:

Message: [TrafficLights] Level loading  [Modding]

(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)

Message: [TrafficLights] Level loaded  [Modding]

(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)

GfxDevice: creating device client; threaded=1
GfxDevice: creating device client; threaded=1
GfxDevice: creating device client; threaded=1
GfxDevice: creating device client; threaded=1
GfxDevice: creating device client; threaded=1
GfxDevice: creating device client; threaded=1
GfxDevice: creating device client; threaded=1
GfxDevice: creating device client; threaded=1
Error: [TrafficLights] SetTool returned null.
Collected tools: System.Collections.Generic.KeyValuePair`2[[System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[ToolBase, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Collections.Generic.KeyValuePair`2[[System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[ToolBase, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Collections.Generic.KeyValuePair`2[[System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[ToolBase, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Collections.Generic.KeyValuePair`2[[System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[ToolBase, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Collections.Generic.KeyValuePair`2[[System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[ToolBase, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Collections.Generic.KeyValuePair`2[[System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[ToolBase, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Collections.Generic.KeyValuePair`2[[System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[ToolBase, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Collections.Generic.KeyValuePair`2[[System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[ToolBase, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Collections.Generic.KeyValuePair`2[[System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[ToolBase, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Collections.Generic.KeyValuePair`2[[System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[ToolBase, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Collections.Generic.KeyValuePair`2[[System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[ToolBase, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Collections.Generic.KeyValuePair`2[[System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[ToolBase, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Collections.Generic.KeyValuePair`2[[System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[ToolBase, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Collections.Generic.KeyValuePair`2[[System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[ToolBase, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Collections.Generic.KeyValuePair`2[[System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[ToolBase, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Collections.Generic.KeyValuePair`2[[System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[ToolBase, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Collections.Generic.KeyValuePair`2[[System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[ToolBase, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Collections.Generic.KeyValuePair`2[[System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[ToolBase, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]
Added Components: DefaultTool, NetTool, BulldozeTool, ZoneTool, BuildingTool, PropTool, TreeTool, TransportTool, DistrictTool, GameAreaTool, CameraTool, IdleTool, TerrainTool, DisasterTool, PropLineTool.PropLineTool, MoveIt.MoveItTool, WaterTool, ResourceTool, SurfacePainter.InGameSurfaceTool, Craxy.CitiesSkylines.ToggleTrafficLights.Tools.JunctionTool  [Modding]

(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)

NullReferenceException: Object reference not set to an instance of an object
  at Craxy.CitiesSkylines.ToggleTrafficLights.Game.Behaviours.MainMachine.ActivateIntersectionTool (Boolean keepInfoMode, Elevation elevation) [0x00000] in <filename unknown>:0 
  at Craxy.CitiesSkylines.ToggleTrafficLights.Game.Behaviours.MainMachine.OnMessage (Message message) [0x00000] in <filename unknown>:0 
  at Craxy.CitiesSkylines.ToggleTrafficLights.Game.Behaviours.MainMachine.Send (Message message) [0x00000] in <filename unknown>:0 
  at Craxy.CitiesSkylines.ToggleTrafficLights.Game.Behaviours.ToggleTrafficLightsButton.OnButtonClick (ColossalFramework.UI.UIComponent _, ColossalFramework.UI.UIMouseEventParameter e) [0x00000] in <filename unknown>:0 
  at ColossalFramework.UI.UIComponent.OnClick (ColossalFramework.UI.UIMouseEventParameter p) [0x00000] in <filename unknown>:0 
  at ColossalFramework.UI.UIButton.OnClick (ColossalFramework.UI.UIMouseEventParameter p) [0x00000] in <filename unknown>:0 
  at ColossalFramework.UI.UIInput+MouseHandler.ProcessInput (IInputTranslator translator, Ray ray, ColossalFramework.UI.UIComponent component, Boolean retainFocusSetting) [0x00000] in <filename unknown>:0 
  at ColossalFramework.UI.UIInput.ProcessMouseInput () [0x00000] in <filename unknown>:0 
  at ColossalFramework.UI.UIInput.Update () [0x00000] in <filename unknown>:0 

(Filename: Line: -1)

(yes -- I forgot that Dictionary returns KeyValuePair ... intended was of course Values -> GetType() instead of KeyValuePairs -> GetType()...)

The used mods are:

PropLineTool and NaturalResourcesBrush both add their tools not only to ToolsModifierControl.m_Tools (dictionary) but to ToolsModifierControl.toolController.m_tools (array) too. TTL only adds the Junction Tool to ToolsModifierControl.m_Tools. Probably one of these tools fill the dictionary with the tools from the array. So if TTL is loaded before (most likely) PropLineTool, the Junction Tool doesn't get added again and is therefore practically removed.

Craxy commented 7 years ago

Changes in 8f6d388: Instead of using ToolsModifierControl.m_Tools and ToolsModifierControl.toolController.m_tools, the Junction Tool isn't added to any of these lists any more. Therefore a special SetTool for junction tool is used that searches in ToolsModifierControl.toolController.GetComponent<> for the JunctionTool. The activation doesn't interfere with any of the internal lists any more. As a result the NullReferenceException should occur for Boehrsi any more, and this issue is (hopefully) fixed.

Issue is kept open until feedback from Boehrsi.

Craxy commented 7 years ago

Feedback from Boehrsi to 8f6d388 (0.10.5) :

works like a charm

-> issue closed