ferram4 / Ferram-Aerospace-Research

Aerodynamics model for Kerbal Space Program
Other
238 stars 131 forks source link

Null-Reference exception when attempting to pull model transforms from a prefab where the transforms do not exist on prefab model #148

Closed shadowmage45 closed 7 years ago

shadowmage45 commented 8 years ago

Have run into reports of this with my mod ( https://github.com/shadowmage45/SSTULabs ), where I add procedurally generated fairings to parts at run-time (not stock fairings though). These fairing transforms and meshes do not exist on the prefab parts, and as such attempting to grab a reference to their transforms from the prefab model will always fail.

Log excerpt from user submission:

NullReferenceException: Object reference not set to an instance of an object
  at FerramAerospaceResearch.FARPartGeometry.GeometryPartModule.GetVisibleMeshData (UnityEngine.Transform t, Boolean onlyMeshes) [0x00000] in <filename unknown>:0 
  at FerramAerospaceResearch.FARPartGeometry.GeometryPartModule.CreateMeshListFromTransforms (System.Collections.Generic.List`1& meshTransforms) [0x00000] in <filename unknown>:0 
  at FerramAerospaceResearch.FARPartGeometry.GeometryPartModule.RebuildAllMeshData () [0x00000] in <filename unknown>:0 
  at FerramAerospaceResearch.FARPartGeometry.GeometryPartModule.GeometryPartModuleRebuildMeshData () [0x00000] in <filename unknown>:0 
UnityEngine.Component:SendMessage(String, Object, SendMessageOptions)
UnityEngine.Component:SendMessage(String)
SSTUTools.SSTUModInterop:onPartGeometryUpdate(Part, Boolean)
SSTUTools.SSTUNodeFairing:buildFairing()
SSTUTools.SSTUNodeFairing:initialize()
SSTUTools.SSTUNodeFairing:OnStart(StartState)
Part:ModulesOnStart()

Locally cloning the FAR repo and adding some debugging to the GetVisibleMeshData method returned the following information:

[LOG 18:43:46.326] mesh filter: FairingPanel-0 (UnityEngine.MeshFilter)
[LOG 18:43:46.327] shared mesh: Procedural Mesh Instance (UnityEngine.Mesh)
[LOG 18:43:46.327] transform from prefab::         

A null-check/wrapper around this code block would 'fix' the problems with these parts:

https://github.com/ferram4/Ferram-Aerospace-Research/blob/master/FerramAerospaceResearch/FARPartGeometry/GeometryPartModule.cs#L667-L668

I am heading out of town for a few days, but will put together a proper PR for this when I return (if it is desired and/or needed).

Thanks in advance :)

ntwest commented 7 years ago

I think this is affecting the Pathfinder parts too?

ferram4 commented 7 years ago

This should be fixed in the latest dev build, so closing.