Skip to content

Commit 7a9a7d4

Browse files
authored
Merge pull request #814 from Csantucci/fix-EOT-train-uncouple-crash
Bug fix for https://bugs.launchpad.net/or/+bug/2013969 Crash after uncoupling player loco of a train with EOT
2 parents 38888b3 + b102c1c commit 7a9a7d4

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

Source/Orts.Simulation/MultiPlayer/Message.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1634,11 +1634,11 @@ public override void HandleMsg() //only client will get message, thus will set s
16341634

16351635
train.MUDirection = (Direction)mDirection;
16361636
train.RearTDBTraveller = traveller;
1637+
train.ReinitializeEOT();
16371638
train.CalculatePositionOfCars();
16381639
train.travelled = Travelled;
16391640
train.CheckFreight();
16401641
train.SetDPUnitIDs();
1641-
train.ReinitializeEOT();
16421642
}
16431643
// New train
16441644
else

Source/Orts.Simulation/Simulation/AIs/AITrain.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -4419,6 +4419,8 @@ public void CoupleAI(Train attachTrain, bool thisTrainFront, bool attachTrainFro
44194419
Cars.Clear();
44204420
attachTrain.Length += Length;
44214421

4422+
attachTrain.ReinitializeEOT();
4423+
44224424
// recalculate position of formed train
44234425
if (attachTrainFront) // coupled to front, so rear position is still valid
44244426
{
@@ -4447,7 +4449,6 @@ public void CoupleAI(Train attachTrain, bool thisTrainFront, bool attachTrainFro
44474449
// set various items
44484450
attachTrain.CheckFreight();
44494451
attachTrain.SetDPUnitIDs();
4450-
attachTrain.ReinitializeEOT();
44514452
attachTrain.activityClearingDistanceM = attachTrain.Cars.Count < standardTrainMinCarNo ? shortClearingDistanceM : standardClearingDistanceM;
44524453
attachCar.SignalEvent(Event.Couple);
44534454

@@ -4533,6 +4534,8 @@ public void CoupleAIToStatic(Train attachTrain, bool thisTrainFront, bool attach
45334534
Length += attachTrain.Length;
45344535
attachTrain.Cars.Clear();
45354536

4537+
ReinitializeEOT();
4538+
45364539
// recalculate position of formed train
45374540
if (thisTrainFront) // coupled to front, so rear position is still valid
45384541
{
@@ -4581,7 +4584,6 @@ public void CoupleAIToStatic(Train attachTrain, bool thisTrainFront, bool attach
45814584
UpdateOccupancies();
45824585
AddTrackSections();
45834586
ResetActions(true);
4584-
ReinitializeEOT();
45854587
physicsUpdate(0);
45864588

45874589
}
@@ -4749,6 +4751,8 @@ public void TerminateCoupling(Train attachTrain, bool thisTrainFront, bool attac
47494751
UncoupledFrom = attachTrain;
47504752
attachTrain.UncoupledFrom = this;
47514753

4754+
ReinitializeEOT();
4755+
attachTrain.ReinitializeEOT();
47524756

47534757
// recalculate position of coupling train
47544758
if (thisTrainFront) // coupled to front, so rear position is still valid
@@ -4809,11 +4813,9 @@ public void TerminateCoupling(Train attachTrain, bool thisTrainFront, bool attac
48094813
// set various items
48104814
CheckFreight();
48114815
SetDPUnitIDs();
4812-
ReinitializeEOT();
48134816
activityClearingDistanceM = Cars.Count < standardTrainMinCarNo ? shortClearingDistanceM : standardClearingDistanceM;
48144817
attachTrain.CheckFreight();
48154818
attachTrain.SetDPUnitIDs();
4816-
attachTrain.ReinitializeEOT();
48174819
attachTrain.activityClearingDistanceM = attachTrain.Cars.Count < standardTrainMinCarNo ? shortClearingDistanceM : standardClearingDistanceM;
48184820
// anticipate reversal point and remove active action
48194821
TCRoute.ReversalInfo[TCRoute.activeSubpath].ReverseReversalOffset = Math.Max(PresentPosition[0].TCOffset - 10f, 0.3f);

Source/Orts.Simulation/Simulation/RollingStocks/TrainCar.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2983,7 +2983,7 @@ internal void UpdateVibrationAndTilting(Traveller traveler, float elapsedTimeS,
29832983

29842984
// Don't add vibrations to train cars less than 2.5 meter in length; they're unsuitable for these calculations.
29852985
// Don't let vibrate car before EOT to avoid EOT not moving together with that car
2986-
if (CarLengthM < 2.5f || Train.EOT != null && Train.Cars[Train.Cars.Count - 2] == this) return;
2986+
if (CarLengthM < 2.5f || Train.EOT != null && Train.Cars.Count > 1 && Train.Cars[Train.Cars.Count - 2] == this) return;
29872987
if (Simulator.Settings.CarVibratingLevel != 0)
29882988
{
29892989

Source/Orts.Simulation/Simulation/Simulator.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,10 @@ public void UncoupleBehind(TrainCar car, bool keepFront)
17491749

17501750
}
17511751

1752+
// update EOT state
1753+
train.ReinitializeEOT();
1754+
train2.ReinitializeEOT();
1755+
17521756
// and fix up the travellers
17531757
if (train.IsActualPlayerTrain && j >= i || !keepFront)
17541758
{
@@ -1846,10 +1850,8 @@ public void UncoupleBehind(TrainCar car, bool keepFront)
18461850

18471851
train.CheckFreight();
18481852
train.SetDPUnitIDs();
1849-
train.ReinitializeEOT();
18501853
train2.CheckFreight();
18511854
train2.SetDPUnitIDs();
1852-
train2.ReinitializeEOT();
18531855

18541856
train.Update(0); // stop the wheels from moving etc
18551857
train2.Update(0); // stop the wheels from moving etc

Source/Orts.Simulation/Simulation/Timetables/TTTrain.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -11705,6 +11705,8 @@ public void TTCouple(TTTrain attachTrain, bool thisTrainFront, bool attachTrainF
1170511705
attachTrain.Length += Length;
1170611706
float distanceTravelledCorrection = 0;
1170711707

11708+
attachTrain.ReinitializeEOT();
11709+
1170811710
// recalculate position of formed train
1170911711
if (attachTrainFront) // coupled to front, so rear position is still valid
1171011712
{
@@ -11769,7 +11771,6 @@ public void TTCouple(TTTrain attachTrain, bool thisTrainFront, bool attachTrainF
1176911771
// set various items
1177011772
attachTrain.CheckFreight();
1177111773
attachTrain.SetDPUnitIDs();
11772-
attachTrain.ReinitializeEOT();
1177311774
attachCar.SignalEvent(Event.Couple);
1177411775
attachTrain.ProcessSpeedSettings();
1177511776

@@ -12105,6 +12106,9 @@ public int TTUncoupleBehind(TTTrain newTrain, bool reverseTrain, int leadLocomot
1210512106

1210612107
}
1210712108

12109+
ReinitializeEOT();
12110+
newTrain.ReinitializeEOT();
12111+
1210812112
// and fix up the travellers
1210912113
if (DetachPosition)
1211012114
{
@@ -12153,10 +12157,8 @@ public int TTUncoupleBehind(TTTrain newTrain, bool reverseTrain, int leadLocomot
1215312157
// check freight for both trains
1215412158
CheckFreight();
1215512159
SetDPUnitIDs();
12156-
ReinitializeEOT();
1215712160
newTrain.CheckFreight();
1215812161
newTrain.SetDPUnitIDs();
12159-
newTrain.ReinitializeEOT();
1216012162

1216112163
// check speed values for both trains
1216212164
ProcessSpeedSettings();

0 commit comments

Comments
 (0)