mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 07:25:47 +03:00
Don't crash in the activity model generators if a map has no borders. This currently happens with Overpass imports. #717
This commit is contained in:
parent
0bce76e172
commit
1d7149c18b
@ -196,9 +196,12 @@ impl PersonFactory {
|
||||
self.find_building_for_activity(activity, current_location, map, rng)
|
||||
{
|
||||
TripEndpoint::Bldg(destination)
|
||||
} else {
|
||||
} else if let Some(i) = commuter_borders.choose(rng) {
|
||||
// No buildings satisfy the activity. Just go somewhere off-map.
|
||||
TripEndpoint::Border(*commuter_borders.choose(rng).unwrap())
|
||||
TripEndpoint::Border(*i)
|
||||
} else {
|
||||
// Broken map without borders. Don't crash, just skip the person
|
||||
continue;
|
||||
};
|
||||
|
||||
let mode = pick_mode(current_location, goto, map, rng, config);
|
||||
|
@ -119,9 +119,8 @@ impl ScenarioGenerator {
|
||||
.filter(|b| b.is_incoming_border())
|
||||
.map(|b| TripEndpoint::Border(b.id))
|
||||
.collect();
|
||||
assert!(!commuter_borders.is_empty());
|
||||
let person_params = (0..num_trips)
|
||||
.map(|_| {
|
||||
.filter_map(|_| {
|
||||
let (is_local_resident, is_local_worker) = (
|
||||
rng.gen_bool(prob_local_resident),
|
||||
rng.gen_bool(prob_local_worker),
|
||||
@ -130,20 +129,20 @@ impl ScenarioGenerator {
|
||||
if let Some(residence) = residents.pop() {
|
||||
TripEndpoint::Bldg(residence)
|
||||
} else {
|
||||
*commuter_borders.choose(rng).unwrap()
|
||||
*commuter_borders.choose(rng)?
|
||||
}
|
||||
} else {
|
||||
*commuter_borders.choose(rng).unwrap()
|
||||
*commuter_borders.choose(rng)?
|
||||
};
|
||||
|
||||
let work = if is_local_worker {
|
||||
if let Some(workplace) = workers.pop() {
|
||||
TripEndpoint::Bldg(workplace)
|
||||
} else {
|
||||
*commuter_borders.choose(rng).unwrap()
|
||||
*commuter_borders.choose(rng)?
|
||||
}
|
||||
} else {
|
||||
*commuter_borders.choose(rng).unwrap()
|
||||
*commuter_borders.choose(rng)?
|
||||
};
|
||||
|
||||
match (&home, &work) {
|
||||
@ -163,7 +162,7 @@ impl ScenarioGenerator {
|
||||
(_, TripEndpoint::SuddenlyAppear(_)) => unreachable!(),
|
||||
};
|
||||
|
||||
(home, work, fork_rng(rng))
|
||||
Some((home, work, fork_rng(rng)))
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user