Fix some crashes with empty cur_blocks
Refuse to give up the last of cur_blocks
using namespace std;
using namespace Msp;
using namespace std;
using namespace Msp;
+namespace {
+
+struct SetFlag
+{
+ bool &flag;
+
+ SetFlag(bool &f): flag(f) { flag = true; }
+ ~SetFlag() { flag = false; }
+};
+
+}
+
+
namespace Marklin {
Train::Train(Layout &l, const VehicleType &t, unsigned a):
namespace Marklin {
Train::Train(Layout &l, const VehicleType &t, unsigned a):
next_route = 0;
end_of_route = false;
next_route = 0;
end_of_route = false;
+ if(route && !cur_blocks.empty())
{
BlockRef &last = (rsv_blocks.empty() ? cur_blocks.back() : rsv_blocks.back());
BlockRef next = last.next();
{
BlockRef &last = (rsv_blocks.empty() ? cur_blocks.back() : rsv_blocks.back());
BlockRef next = last.next();
float Train::get_reserved_distance() const
{
float Train::get_reserved_distance() const
{
+ if(cur_blocks.empty())
+ return 0;
+
Vehicle &veh = *(reverse ? vehicles.back() : vehicles.front());
const VehicleType &vtype = veh.get_type();
Vehicle &veh = *(reverse ? vehicles.back() : vehicles.front());
const VehicleType &vtype = veh.get_type();
float d = get_real_speed(current_speed)*(dt/Time::sec);
if(ok)
{
float d = get_real_speed(current_speed)*(dt/Time::sec);
if(ok)
{
+ SetFlag setf(advancing);
vehicle.advance(reverse ? -d : d);
vehicle.advance(reverse ? -d : d);
}
else if(accurate_position)
{
}
else if(accurate_position)
{
- if(end!=cur_blocks.begin())
+ if(end!=cur_blocks.begin() && end!=cur_blocks.end())
// Free blocks up to the last inactive sensor
release_blocks(cur_blocks, cur_blocks.begin(), end);
}
// Free blocks up to the last inactive sensor
release_blocks(cur_blocks, cur_blocks.begin(), end);
}
+ SetFlag setf(reserving);
bool got_more = false;
BlockRef *good = last;
bool got_more = false;
BlockRef *good = last;
last = &rsv_blocks.back();
}
last = &rsv_blocks.back();
}
// Make any sensorless blocks at the beginning immediately current
list<BlockRef>::iterator i;
// Make any sensorless blocks at the beginning immediately current
list<BlockRef>::iterator i;