Skip to content

Commit 2ba7b95

Browse files
committed
temporary fix for bug 2121985: F9 TCO out-of-range after resume
This is a temporary fix. It prevents writing an out of range index into the save file. As a comment it contains a better fix for the Window, but I could not come up with a simple fix for the Webpage.
1 parent 0143dee commit 2ba7b95

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

Source/RunActivity/Viewer3D/Popups/TrainCarOperationsViewerWindow.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
using ORTS.Common.Input;
3030
using System;
3131
using System.Collections.Generic;
32+
using System.Diagnostics;
3233
using System.IO;
3334
using System.Linq;
3435

@@ -167,6 +168,12 @@ protected internal override void Save(BinaryWriter outf)
167168
outf.Write(Location.Width);
168169
outf.Write(Location.Height);
169170

171+
// rwf-rr: temporary fix for bug 2121985
172+
if (CarPosition >= Owner.Viewer.PlayerTrain.Cars.Count)
173+
{
174+
Trace.TraceWarning("TrainCarOperationsViewerWindow.CarPosition {0} out of range [0..{1}]", CarPosition, Owner.Viewer.PlayerTrain.Cars.Count - 1);
175+
CarPosition = Owner.Viewer.PlayerTrain.Cars.Count - 1;
176+
}
170177
outf.Write(CarPosition);
171178
outf.Write(ResetAllSymbols);
172179
}
@@ -574,6 +581,9 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
574581

575582
//required by traincarwindow to ModifyWindowSize()
576583
windowHeight = Vbox != null ? Vbox.Position.Height : 0;
584+
585+
// rwf-rr: part of debugging bug 2121985
586+
// System.Diagnostics.Debug.Assert(CarPosition < PlayerTrain.Cars.Count, "Viewer SelectedCar (index) out of range");
577587
}
578588
}
579589

Source/RunActivity/Viewer3D/Popups/TrainCarOperationsWindow.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
using Orts.Viewer3D.RollingStock;
3636
using Orts.MultiPlayer;
3737
using Orts.Viewer3D;
38+
using System.Diagnostics;
3839

3940
namespace Orts.Viewer3D.Popups
4041
{
@@ -178,6 +179,12 @@ protected internal override void Save(BinaryWriter outf)
178179
outf.Write(Location.Width);
179180
outf.Write(Location.Height);
180181

182+
// rwf-rr: temporary fix for bug 2121985
183+
if (SelectedCarPosition >= Owner.Viewer.PlayerTrain.Cars.Count)
184+
{
185+
Trace.TraceWarning("TrainCarOperationsWindow.SelectedCarPosition {0} out of range [0..{1}]", SelectedCarPosition, Owner.Viewer.PlayerTrain.Cars.Count - 1);
186+
SelectedCarPosition = Owner.Viewer.PlayerTrain.Cars.Count - 1;
187+
}
181188
outf.Write(SelectedCarPosition);
182189
outf.Write(Owner.Viewer.FrontCamera.IsCameraFront);
183190
}
@@ -642,6 +649,13 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
642649
SupplyStatusChanged = false;
643650
Layout();
644651
updateLayoutSize();
652+
653+
// rwf-rr: potential partial fix for bug 2121985
654+
// if (trainCarViewer.CouplerChanged && CarPosition >= Owner.Viewer.PlayerTrain.Cars.Count)
655+
// {
656+
// SelectedCarPosition = CarPosition = Owner.Viewer.PlayerTrain.Cars.Count - 1;
657+
// LastCarIDSelected = PlayerTrain.Cars[SelectedCarPosition].CarID;
658+
// }
645659
}
646660
if (OldPositionHeight != Vbox.Position.Height)
647661
{
@@ -754,6 +768,11 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
754768
FontToBold = !FontToBold;
755769
UpdateWindowSize();
756770
}
771+
772+
// rwf-rr: part of debugging bug 2121985
773+
// System.Diagnostics.Debug.Assert(SelectedCarPosition < Owner.Viewer.PlayerTrain.Cars.Count, "Window SelectedCarPosition (index) out of range");
774+
// System.Diagnostics.Debug.Assert(CarPosition < Owner.Viewer.PlayerTrain.Cars.Count, "Window SelectedCar (index) out of range");
775+
// System.Diagnostics.Debug.Assert(CurrentCarPosition < Owner.Viewer.PlayerTrain.Cars.Count, "Window CurrentCarPosition (index) out of range");
757776
}
758777
}
759778

Source/RunActivity/Viewer3D/WebServices/TrainCarOperationsWebpage.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ public void handleReceiveAndSend()
233233
public void Save(BinaryWriter outf)
234234
{
235235
outf.Write(TrainCarSelected);
236+
// rwf-rr: temporary fix for bug 2121985
237+
if (TrainCarSelectedPosition >= Viewer.PlayerTrain.Cars.Count)
238+
{
239+
Trace.TraceWarning("TrainCarOperationsWebpage.TrainCarSelectedPosition {0} out of range [0..{1}]", TrainCarSelectedPosition, Viewer.PlayerTrain.Cars.Count - 1);
240+
TrainCarSelectedPosition = Viewer.PlayerTrain.Cars.Count - 1;
241+
}
236242
outf.Write(TrainCarSelectedPosition);
237243
}
238244

@@ -371,6 +377,9 @@ private void fillStatus(OperationsStatus operationStatus)
371377

372378
carPosition++;
373379
}
380+
381+
// rwf-rr: part of debugging bug 2121985
382+
// System.Diagnostics.Debug.Assert(TrainCarSelectedPosition < Viewer.PlayerTrain.Cars.Count, "Web TrainCarSelectedPosition (index) out of range");
374383
}
375384

376385
private string getCarId(TrainCar trainCar, int carPosition)

0 commit comments

Comments
 (0)