Add a sanity check to catch live map edit bugs faster. Deleted turns

aren't getting cleaned up properly.

Also fix broken headless build, woops.
This commit is contained in:
Dustin Carlino 2020-10-21 10:23:56 -07:00
parent e9f9d3884b
commit a579cb4f74
4 changed files with 35 additions and 1 deletions

View File

@ -295,7 +295,7 @@ fn handle_command(
.get_unzoomed_agents(map) .get_unzoomed_agents(map)
.into_iter() .into_iter()
.map(|a| AgentPosition { .map(|a| AgentPosition {
vehicle_type: a.vehicle_type, vehicle_type: a.id.to_vehicle_type(),
pos: a.pos.to_gps(map.get_gps_bounds()), pos: a.pos.to_gps(map.get_gps_bounds()),
person: a.person, person: a.person,
}) })

View File

@ -549,6 +549,34 @@ impl IntersectionSimState {
} }
} }
} }
pub fn handle_live_edits(&self, map: &Map) {
// Just sanity check that we don't have any references to deleted turns
let mut errors = Vec::new();
for state in self.state.values() {
for req in &state.accepted {
if map.maybe_get_t(req.turn).is_none() {
errors.push(format!("{} accepted for {}", req.agent, req.turn));
}
}
for req in state.waiting.keys() {
if map.maybe_get_t(req.turn).is_none() {
errors.push(format!("{} waiting for {}", req.agent, req.turn));
}
}
for req in &state.reserved {
if map.maybe_get_t(req.turn).is_none() {
errors.push(format!("{} has reserved {}", req.agent, req.turn));
}
}
}
if !errors.is_empty() {
for x in errors {
error!("{}", x);
}
panic!("After live map edits, intersection state refers to deleted turns!");
}
}
} }
impl IntersectionSimState { impl IntersectionSimState {

View File

@ -926,6 +926,8 @@ impl Sim {
AgentID::BusPassenger(_, _) => unreachable!(), AgentID::BusPassenger(_, _) => unreachable!(),
} }
} }
self.intersections.handle_live_edits(map);
} }
fn find_trips_affected_by_live_edits(&mut self, map: &Map) -> Vec<(AgentID, TripID)> { fn find_trips_affected_by_live_edits(&mut self, map: &Map) -> Vec<(AgentID, TripID)> {

View File

@ -34,6 +34,9 @@ fn main() {
if let Err(err) = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { if let Err(err) = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
run(&mut map, &mut sim, &mut rng, &mut timer); run(&mut map, &mut sim, &mut rng, &mut timer);
})) { })) {
let mut edits = map.get_edits().clone();
edits.edits_name = "traffic_seitan_crash".to_string();
map.must_apply_edits(edits, &mut timer);
map.save_edits(); map.save_edits();
println!("Crashed at {}", sim.time()); println!("Crashed at {}", sim.time());
@ -49,6 +52,7 @@ fn run(map: &mut Map, sim: &mut Sim, rng: &mut XorShiftRng, timer: &mut Timer) {
println!(""); println!("");
sim.timed_step(map, edit_frequency, &mut None, timer); sim.timed_step(map, edit_frequency, &mut None, timer);
sim.save(); sim.save();
map.save_edits();
let mut edits = map.get_edits().clone(); let mut edits = map.get_edits().clone();
nuke_random_parking(map, rng, &mut edits); nuke_random_parking(map, rng, &mut edits);