boformer / BuildingThemes

Mod for Cities:Skylines
http://steamcommunity.com/sharedfiles/filedetails/?id=466158459
MIT License
13 stars 11 forks source link

nullRefException in ZoneBlock.SimulationStep #59

Closed boformer closed 9 years ago

boformer commented 9 years ago
Object reference not set to an instance of an object [System.NullReferenceException]

Details:
No details
System.NullReferenceException: Object reference not set to an instance of an object
  at BuildingThemes.Detour.ZoneBlockDetour.SimulationStep (UInt16 blockID) [0x00000] in <filename unknown>:0 
  at ZoneManager.SimulationStepImpl (Int32 subStep) [0x00000] in <filename unknown>:0 
  at SimulationManagerBase`2[Manager,Properties].SimulationStep (Int32 subStep) [0x00000] in <filename unknown>:0 
  at ZoneManager.ISimulationManager.SimulationStep (Int32 subStep) [0x00000] in <filename unknown>:0 
  at SimulationManager.SimulationStep () [0x00000] in <filename unknown>:0 
  at SimulationManager.SimulationThread () [0x00000] in <filename unknown>:0 

Description:

SamsamTS commented 9 years ago

Could prop be null in ZoneBlockDetour at Line 754?

foreach (var prop in buildingInfo.m_props)

It's the only thing I can see that would throw a NullReferenceException in SimulationStep.

boformer commented 9 years ago

Yes, maybe m_props is null in some cases.

SamsamTS commented 9 years ago

What I had in mind is that if prop is null then it would throw an exception when you try to access m_position on the next line :

biggestPropPosZ = Mathf.Max(biggestPropPosZ, buildingInfo.m_expandFrontYard ? prop.m_position.z : -prop.m_position.z);

so maybe you should add a test, it wouldn't hurt.

if (prop != null) biggestPropPosZ = Mathf.Max(biggestPropPosZ, buildingInfo.m_expandFrontYard ? prop.m_position.z : -prop.m_position.z);

EDIT: But I guess if m_prop is null it would also throw a NullReferenceException

boformer commented 9 years ago

I pushed a fix to master. Do you know how to enable line numbers in exceptions? That would be so helpful.

SamsamTS commented 9 years ago

The game isn't compiled in debug mode so no line numbers unfortunately. Maybe with a hacked mono VM or something.

boformer commented 9 years ago

Nailed it down. This is the issue: Image