Skip to content

Commit

Permalink
Don't crash when following a bus that's finished. #372 [rebuild] [rel…
Browse files Browse the repository at this point in the history
…ease]

The UX of bus info panels is terrible, but just unbreak this.
  • Loading branch information
dabreegster committed Apr 17, 2022
1 parent 7b77b07 commit 7f50baa
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions sim/src/transit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum BusState {
AtStop(StopIdx),
// Or to the end of the lane with the last stop
DrivingOffMap,
Finished,
}

/// Manages public transit vehicles (buses and trains) that follow a route. The transit model is
Expand Down Expand Up @@ -206,18 +207,17 @@ impl TransitSimState {
}
trips.transit_rider_reached_border(now, person, id, ctx);
}
self.buses.remove(&id).unwrap();
bus.state = BusState::Finished;
false
}
BusState::AtStop(_) => unreachable!(),
BusState::AtStop(_) | BusState::Finished => unreachable!(),
}
}

pub fn bus_departed_from_stop(&mut self, id: CarID, _: &Map) -> Router {
let mut bus = self.buses.get_mut(&id).unwrap();
let route = self.routes.get_mut(&bus.route).unwrap();
match bus.state {
BusState::DrivingToStop(_) | BusState::DrivingOffMap => unreachable!(),
BusState::AtStop(stop_idx) => {
self.events.push(Event::BusDepartedFromStop(
id,
Expand All @@ -232,6 +232,9 @@ impl TransitSimState {
}
Router::follow_bus_route(id, route.paths[stop_idx + 1].clone())
}
BusState::DrivingToStop(_) | BusState::DrivingOffMap | BusState::Finished => {
unreachable!()
}
}
}

Expand Down Expand Up @@ -310,6 +313,7 @@ impl TransitSimState {
}
BusState::AtStop(idx) => Some(idx),
BusState::DrivingOffMap => Some(r.stops.len() - 1),
BusState::Finished => unreachable!(),
};
(*bus, stop)
})
Expand Down

0 comments on commit 7f50baa

Please sign in to comment.