mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-01 02:33:54 +03:00
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:
parent
e9f9d3884b
commit
a579cb4f74
@ -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,
|
||||||
})
|
})
|
||||||
|
@ -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 {
|
||||||
|
@ -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)> {
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user