File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
Source/Orts.Simulation/Simulation/Physics Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -5591,19 +5591,22 @@ public void UpdateCouplerSlack(float elapsedTime)
55915591 car.DistanceM += Math.Abs(car.SpeedMpS * elapsedTime);
55925592
55935593 // Identify links to cars ahead and behind for use when animating couplers
5594- if (j == 0)
5594+ if (j == 0) // typically the locomotive
55955595 {
55965596 car.CarAhead = null;
55975597 if (Cars.Count > j) // if not a single loco
55985598 {
5599- car.CarBehind = Cars[j + 1];
5599+ if (j != Cars.Count - 1) // if so, this is the last car, and hence no cars behind it
5600+ {
5601+ car.CarBehind = Cars[j + 1];
5602+ }
56005603 }
56015604 else // if a single loco
56025605 {
56035606 car.CarBehind = null;
56045607 }
56055608 }
5606- else if (j == Cars.Count - 1)
5609+ else if (j == Cars.Count - 1) // last car in train
56075610 {
56085611 Cars[j].CarAhead = Cars[j - 1];
56095612 Cars[j].CarBehind = null;
You can’t perform that action at this time.
0 commit comments