@@ -277,9 +277,26 @@ public class PoseableShape : StaticShape
277277 public PoseableShape ( Viewer viewer , string path , WorldPosition initialPosition , ShapeFlags flags )
278278 : base ( viewer , path , initialPosition , flags )
279279 {
280- XNAMatrices = new Matrix [ SharedShape . Matrices . Length ] ;
281- for ( int iMatrix = 0 ; iMatrix < SharedShape . Matrices . Length ; ++ iMatrix )
282- XNAMatrices [ iMatrix ] = SharedShape . Matrices [ iMatrix ] ;
280+ if ( SharedShape . Matrices . Length > 0 )
281+ {
282+ XNAMatrices = new Matrix [ SharedShape . Matrices . Length ] ;
283+ for ( int iMatrix = 0 ; iMatrix < SharedShape . Matrices . Length ; ++ iMatrix )
284+ XNAMatrices [ iMatrix ] = SharedShape . Matrices [ iMatrix ] ;
285+ }
286+ else // If the shape file is missing or fails to load, we need some default data to prevent crashes
287+ {
288+ if ( path != null && path != "Empty" )
289+ {
290+ string location = path ;
291+ if ( path != null && path . Contains ( '\0 ' ) )
292+ location = path . Split ( '\0 ' ) [ 0 ] ;
293+
294+ Trace . TraceWarning ( "Couldn't load shape {0} file may be corrupt" , location ) ;
295+ }
296+ // The 0th matrix should always be the identity matrix
297+ XNAMatrices = new Matrix [ 1 ] ;
298+ XNAMatrices [ 0 ] = Matrix . Identity ;
299+ }
283300
284301 if ( SharedShape . LodControls . Length > 0 && SharedShape . LodControls [ 0 ] . DistanceLevels . Length > 0 && SharedShape . LodControls [ 0 ] . DistanceLevels [ 0 ] . SubObjects . Length > 0 && SharedShape . LodControls [ 0 ] . DistanceLevels [ 0 ] . SubObjects [ 0 ] . ShapePrimitives . Length > 0 )
285302 Hierarchy = SharedShape . LodControls [ 0 ] . DistanceLevels [ 0 ] . SubObjects [ 0 ] . ShapePrimitives [ 0 ] . Hierarchy ;
0 commit comments