Looky1173 / launchpad-bugs-migration2

0 stars 0 forks source link

[BUG n°1892330] System.ArgumentOutOfRangeException at Orts.Simulation.Physics.Train.SetFormedOccupied (1.3.1.4328) #2329

Open Looky1173 opened 4 years ago

Looky1173 commented 4 years ago

Imported from https://bugs.launchpad.net/bugs/1892330

Property Value
Reported by Bela Tegi (abelino)
Date reported Thu, 20 Aug 2020 08:42:44 GMT
Tags crash, physics

Hi!

Timetable, formed train from arrived train (#dispose - $forms=...), when starting this activity occured the exception.

I debugged code and found in Orts.Simulation/Simulation/Physics/Train.cs, SetFormedOccupied() method: for (int iRouteIndex = rearIndex; iRouteIndex <= frontIndex; iRouteIndex++) where rearIndex and frontIndex was -1, and later use iRouteIndex as array element indexer, which lead to exception.

(FYI: When I NOT used forms in dispose row (not formed train), this exception not happen.)

Br.: abelino

Looky1173 commented 4 years ago

Imported from https://bugs.launchpad.net/or/+bug/1892330/comments/1

Property Value
Posted by Bela Tegi (abelino)
Date posted Thu, 20 Aug 2020 08:42:44 GMT
Looky1173 commented 4 years ago

Imported from https://bugs.launchpad.net/or/+bug/1892330/comments/2

Property Value
Posted by Bela Tegi (abelino)
Date posted Sun, 23 Aug 2020 08:37:24 GMT

Hi!

(I was a little free time, so I found one solution.)

Add few lines of code to Orts.Simulation/Simulation/Timetables/TTTrain.cs in "void FormTrainFromAI(int presentTime)" method:

if (validFormed) { +++ formedTrain.PresentPosition[0].RouteListIndex = PresentPosition[0].RouteListIndex; +++ formedTrain.PresentPosition[0].TCOffset = PresentPosition[0].TCOffset; +++ formedTrain.PresentPosition[0].TCSectionIndex = PresentPosition[0].TCSectionIndex; +++ formedTrain.PresentPosition[1].RouteListIndex = PresentPosition[1].RouteListIndex; +++ formedTrain.PresentPosition[1].TCOffset = PresentPosition[1].TCOffset; +++ formedTrain.PresentPosition[1].TCSectionIndex = PresentPosition[1].TCSectionIndex; // start new train if (!autogenStart) { AI.Simulator.StartReference.Remove(formedTrain.Number); }

Important! This patch resolves this issue, but I don't know, what else breaks!

Br: abelino