Skip to content

Commit a30c659

Browse files
committed
handles missing SD file
1 parent 6c1eb75 commit a30c659

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

Source/Orts.Formats.Msts/ShapeDescriptorFile.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
using System;
1919
using System.Collections.Generic;
20-
2120
using Orts.Parsers.Msts;
2221

2322
namespace Orts.Formats.Msts
@@ -36,12 +35,19 @@ public class ShapeDescriptorFile
3635
public ShapeDescriptorFile(string filename)
3736
{
3837
var shapeDescriptorPath = filename.ToLowerInvariant();
38+
3939
if (Cache.ContainsKey(shapeDescriptorPath))
4040
{
4141
shape = Cache[shapeDescriptorPath];
4242
}
4343
else
4444
{
45+
if (!System.IO.File.Exists(filename)) // If not found, skip
46+
{
47+
shape = null;
48+
return;
49+
}
50+
4551
using (STFReader stf = new STFReader(filename, false))
4652
{
4753
stf.ParseFile(new STFReader.TokenProcessor[] {

Source/RunActivity/Viewer3D/Scenery.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -345,19 +345,16 @@ public WorldFile(Viewer viewer, int tileX, int tileZ, bool visible)
345345
if (shapeFilePath != null)
346346
{
347347
var shape = new ShapeDescriptorFile(shapeDescriptorPath);
348-
if (shape != null)
348+
if (shape.shape?.ESD_Bounding_Box != null)
349349
{
350-
if (shape.shape.ESD_Bounding_Box != null)
351-
{
352-
var min = shape.shape.ESD_Bounding_Box.Min;
353-
var max = shape.shape.ESD_Bounding_Box.Max;
354-
var transform = Matrix.Invert(worldMatrix.XNAMatrix);
355-
// Not sure if this is needed, but it is to correct for center-of-gravity being not the center of the box.
356-
//transform.M41 += (max.X + min.X) / 2;
357-
//transform.M42 += (max.Y + min.Y) / 2;
358-
//transform.M43 += (max.Z + min.Z) / 2;
359-
BoundingBoxes.Add(new BoundingBox(transform, new Vector3((max.X - min.X) / 2, (max.Y - min.Y) / 2, (max.Z - min.Z) / 2), worldMatrix.XNAMatrix.Translation.Y));
360-
}
350+
var min = shape.shape.ESD_Bounding_Box.Min;
351+
var max = shape.shape.ESD_Bounding_Box.Max;
352+
var transform = Matrix.Invert(worldMatrix.XNAMatrix);
353+
// Not sure if this is needed, but it is to correct for center-of-gravity being not the center of the box.
354+
//transform.M41 += (max.X + min.X) / 2;
355+
//transform.M42 += (max.Y + min.Y) / 2;
356+
//transform.M43 += (max.Z + min.Z) / 2;
357+
BoundingBoxes.Add(new BoundingBox(transform, new Vector3((max.X - min.X) / 2, (max.Y - min.Y) / 2, (max.Z - min.Z) / 2), worldMatrix.XNAMatrix.Translation.Y));
361358
}
362359
}
363360

0 commit comments

Comments
 (0)