Elvas Tower: Crash in UpdateCarSpeeds (Train.cs) - Elvas Tower

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Crash in UpdateCarSpeeds (Train.cs) Rate Topic: -----

#1 User is offline   roeter 

  • Vice President
  • Group: Status: Elite Member
  • Posts: 2,424
  • Joined: 25-October 11
  • Gender:Male
  • Country:

Posted 04 August 2023 - 01:35 PM

Tonight, I ran into an unexpected but consistent crash in UpdateCarSpeeds, in Train.cs.
I cannot give you the log-file as line numbers in my version will differ from the official versions, so instead I will give you the code. It is quite easy to locate.

            //
            // start cars moving backward when it is stationary, once it is moving it skips this whole section
            //
            for (int i = Cars.Count - 1; i >= 0; i--)
            {
                TrainCar car = Cars[i];
                if (car.SpeedMpS != 0 || car.TotalForceN > (-1.0f * (car.FrictionForceN + car.BrakeForceN + car.CurveForceN + car.WindForceN + car.TunnelForceN)))
                {
                    // Skip this section to start car if car is already moving, or force not sufficient to start it moving
                    continue;
                }
                int j = i;
                float f = 0;
                float m = 0;
                for (; ; )
                {
                    // Cycle up the train consist until the first stationary car is found that has its leading couplers starting to pull it. The next car is then started by allowing its speed to increase above 0.
                    f += car.TotalForceN + car.FrictionForceN + car.BrakeForceN + car.CurveForceN + car.WindForceN + car.TunnelForceN;
                    m += car.MassKG;
                    if (car.IsPlayerTrain && !Simulator.Settings.SimpleControlPhysics && car.IsAdvancedCoupler) // "Advanced coupler" - operates in three extension zones
                    {
                        if (j == 0 || car.CouplerSlackM > car.AdvancedCouplerDynamicCompressionSlackLimitM)
                            break;
                    }
                    else // Simple coupler
                    {
                        if (j == 0 || car.CouplerSlackM > -car.GetMaximumSimpleCouplerSlack2M())
                            break;
                    }
                    j--;
                    // Decrement the count so that next car is started
                    car = Cars[j];
                }
                if (f < 0)
                {
                    for (int k = j; k <= i; k++)
                    {
                        
                        if ((Cars[k].CarBrakeSystemType == "air_piped" || Cars[k].CarBrakeSystemType == "vacuum_piped" || car.CarBrakeSystemType == "manual_braking") && FirstCar.SpeedMpS > 0 && Cars[k - 1].SpeedMpS == 0.0)    <==== CRASH
                        {
                            // If is manual braked, air_piped car or vacuum_piped, and preceeding car is at stop, then set speed to zero.  These type of cars do not have any brake force to hold them still
                            Cars[k].SpeedMpS = 0.0f;
                        }
                        else
                        {
                            // Start this stationary car
                            Cars[k].SpeedMpS = f / m * elapsedTime;
                        }
                    }
                }
            }
        }



In the code above, I have indicated the line where the crash occurs.
Looking into this (using some additional print statements), what happens is that the first loop (for ( ; ; ; )) exits with j=0.
In that case, the second loop (for (int k = j; k <= i; k++)) runs from 0 to 1, and not surprisingly, the IF statement then crashes on Cars[k-1].

The crash occurs as cars are attached, for the previous update showed the train had 7 cars, but at the moment of the crash it has 10 cars.

The crash occured on the New Forest route, just after 09:15. Restarting from saved sessions just before it happened (thanks to my auto-save), it was consistent. But that does not mean it is also consistent when starting completely fresh.

Regards,
Rob Roeterdink

#2 User is offline   rickloader 

  • Conductor
  • Group: Status: First Class
  • Posts: 493
  • Joined: 05-February 13
  • Gender:Male
  • Location:Southampton uk
  • Simulator:Open Rails
  • Country:

Posted 05 August 2023 - 12:08 AM

Is this a train from the New Forest timetable? Would it help if I ran the train and posted the log using the current unstable version?
Thanks for using NF route as a test environment
Rick

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users