From: Mikko Rasa Date: Fri, 9 Aug 2013 10:32:14 +0000 (+0300) Subject: Avoid infinite loops in VehiclePlacement in certain situations X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=7e7cb480bc83406b0ad1cc5cb1e07cc953f49a7d;p=r2c2.git Avoid infinite loops in VehiclePlacement in certain situations --- 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