Thread hang exception on circle loops (case 3)

Bug #1450844 reported by Carlo Santucci
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Open Rails
Fix Released
Undecided
r.roeterdink

Bug Description

This route http://www.trainsimhobby.net/infusions/pro_download_panel/download.php?did=761 seems to challenge OR quite much.
I got another type of thread hang exception in such route.
The loop occurs in this section of GetDistanceBetweenObjects in Signals.cs:
            while (thisSectionIndex != endSectionIndex && thisSectionIndex > 0)
            {
                distanceM += thisSection.Length;
                TrPin nextLink = thisSection.GetNextActiveLink(direction, lastIndex);

                lastIndex = thisSectionIndex;
                thisSectionIndex = nextLink.Link;
                direction = nextLink.Direction;

                if (thisSectionIndex > 0)
                    thisSection = signalRef.TrackCircuitList[thisSectionIndex];
            }

As can be seen, if thisSectionIndex remains >0, this while can be endless if the switches are thrown in a way that a circular loop is generated. This method is indirectly called by line 3052 of signals.cs
                clearedDistanceM = thisTrain.Train.GetDistanceToTrain(lastReserved, 0.0f);
I wonder if it is correct to use this way to compute the distance here (as we are computing distance along the train path), or if it would be more correct to add the route section lengths without looking at the state of the switches.

Attached: logfile and route. The hang was obtained by using Autopilot, but I didn't check if it was caused by the player train or by one of the AI trains (that have all the same service).

Tags: crash signals
Revision history for this message
Carlo Santucci (carlosanit1) wrote :
Revision history for this message
Carlo Santucci (carlosanit1) wrote :

The hang occurs about after 5 minutes of game.

Revision history for this message
r.roeterdink (r-roeterdink) wrote :

The program correctly follows the actual train route, problem here is that the actual route is indeed looped - it's a full circle, without any objects to 'stop' the search.
A loop detection has been added, setting the resulting length to the value as found when the loop occurs.
Committed in version 3053.

Revision history for this message
Carlo Santucci (carlosanit1) wrote :

Thanks Rob,
now it works. I made a wrong comment about the program not following the train route, because I had in mind another case.

jeroenp (j-paasschens)
Changed in or:
status: New → Fix Committed
James Ross (twpol)
Changed in or:
assignee: nobody → r.roeterdink (r-roeterdink)
milestone: none → 1.0
James Ross (twpol)
Changed in or:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.