Skip to content

Commit 9b0ec01

Browse files
committed
Detect and mitigate corrupt shape files to reduce crash risk
1 parent bc806e2 commit 9b0ec01

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

Source/RunActivity/Viewer3D/Shapes.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,20 @@ 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+
// In some cases, a corrupt shape file can prevent matrices from loading
281+
if (SharedShape.Matrices.Length > 0)
282+
{
283+
XNAMatrices = new Matrix[SharedShape.Matrices.Length];
284+
for (int iMatrix = 0; iMatrix < SharedShape.Matrices.Length; ++iMatrix)
285+
XNAMatrices[iMatrix] = SharedShape.Matrices[iMatrix];
286+
}
287+
else
288+
{
289+
Trace.TraceWarning("Could not determine matrices for shape file {0} file may be corrupt", SharedShape.FilePath);
290+
// The 0th matrix should always be the identity matrix, add this to avoid crashes elsewhere
291+
XNAMatrices = new Matrix[1];
292+
XNAMatrices[0] = Matrix.Identity;
293+
}
283294

284295
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)
285296
Hierarchy = SharedShape.LodControls[0].DistanceLevels[0].SubObjects[0].ShapePrimitives[0].Hierarchy;

0 commit comments

Comments
 (0)