Saturday 11 November 2017

TrafficControl: Crash When Using a Network Without Coordinates

In a previous blog post, I've seen that the program asserts when using a network without coordinates.

The assert is trigged when the train is in state "RUNNING":

After adding prints, I've seen that the issue comes when the train is in Train::runningState. The train tries to set the new position on the track using this->setTrackPosition.

The train is trying to get coordinates for a position on the track. But as the track has no coordinates, the code asserts.

The program is trying to act on the coordinateList that doesn't exist,
One solution can be to check if the coordinateList has length = 0. If that is the case, return 0. Also, the calling program should check if the track has coordinates. I'll add a boolean hasCoordinates to Track, and a corresponding get method.

The fix for train::setTrackPosition() is:

No comments:

Post a Comment