From 7e7cb480bc83406b0ad1cc5cb1e07cc953f49a7d Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 9 Aug 2013 13:32:14 +0300 Subject: [PATCH] Avoid infinite loops in VehiclePlacement in certain situations --- source/libr2c2/vehicleplacement.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/libr2c2/vehicleplacement.cpp b/source/libr2c2/vehicleplacement.cpp index 9f9001f..5bf9899 100644 --- a/source/libr2c2/vehicleplacement.cpp +++ b/source/libr2c2/vehicleplacement.cpp @@ -51,6 +51,9 @@ VehiclePlacement::VehiclePlacement(const VehicleType &t): void VehiclePlacement::place(const TrackOffsetIter &p, Anchor a) { + if(!p) + return unplace(); + float anchor = get_anchor_position(a); for(vector::iterator i=axles.begin(); i!=axles.end(); ++i) @@ -246,9 +249,9 @@ float VehiclePlacement::compute_adjustment(const Vector &p1, const Vector &p2, f float span = distance(p1, p2); float adjust = target-span; - /* If the adjustment is larger than the last one, we've hit a gap or + /* If the adjustment is not smaller than the last one, we've hit a gap or other oddity in the track. Terminate to avoid an infinite loop. */ - if(last>0 && abs(adjust)>last) + if(last>0 && abs(adjust)>=last) return 0; if(abs(adjust)*10000