a-b-street/abstreet · error

trying to make a crossing_state from to at . Something's…

Error message

{} trying to make a crossing_state from {} to {} at {}. Something's very wrong

What it means

crossing_state computes the car's end distance along the current lane and requires it to be at or ahead of the start distance; a car cannot traverse a lane backwards. If end_dist < start_dist the car's routing/position state is inconsistent, so the simulation panics with the vehicle id, both distances, and time for diagnosis.

Solutions

  1. Recompute or clamp car distances after applying map edits (recalculate paths/distances)
  2. Reproduce with the printed vehicle id and inspect its router state at that time
  3. Report/fix upstream — this indicates a simulation invariant bug, not bad user input

Example fix

// defensive clamp before constructing
let end_dist = end_dist.max(start_dist);
let dist_int = DistanceInterval::new_driving(start_dist, end_dist);
Defensive patterns

Strategy: try-catch

Validate before calling

// before driving: ensure car distances fit the current (possibly edited) map
assert!(car_dist <= map.get_l(lane).length());

Try / catch

std::panic::catch_unwind(|| sim.step(&mut timer))
    .map_err(|_| format!("sim crashed; see vehicle id in panic output"));

Prevention

When it happens

Trigger: start_car_on_lane (or lane-changing into crossing_state) where router.get_end_dist()/lane length yields an end_dist smaller than start_dist — e.g. after map edits shorten the lane below the car's stored distance, or stale router state after a path change.

Common situations: Applying edits that shorten lanes mid-simulation; cars mid-lane-change onto a lane shorter than their current offset; bugs in router end-dist bookkeeping on the final step.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of a-b-street/abstreet@0964f29315 (2026-09-13). Data as JSON: /api/errors/fb508b5ee1f21313. Report an issue: GitHub.

Appendix: source

Thrown at sim/src/mechanics/car.rs:43

    /// In reverse order -- most recently left is first. The sum length of these must be >=
    /// vehicle.length.
    pub last_steps: VecDeque<Traversable>,

    /// Since lane over-taking isn't implemented yet, a vehicle tends to be stuck behind a slow
    /// leader for a while. Avoid duplicate events.
    pub wants_to_overtake: BTreeSet<CarID>,
}

impl Car {
    /// Assumes the current head of the path is the thing to cross.
    pub fn crossing_state(&self, start_dist: Distance, start_time: Time, map: &Map) -> CarState {
        let end_dist = if self.router.last_step() {
            self.router.get_end_dist()
        } else {
            self.router.head().get_polyline(map).length()
        };
        if end_dist < start_dist {
            panic!(
                "{} trying to make a crossing_state from {} to {} at {}. Something's very wrong",
                self.vehicle.id, start_dist, end_dist, start_time
            );
        }

        let dist_int = DistanceInterval::new_driving(start_dist, end_dist);
        self.crossing_state_with_end_dist(dist_int, start_time, map)
    }

    pub fn crossing_state_with_end_dist(
        &self,
        dist_int: DistanceInterval,
        start_time: Time,
        map: &Map,
    ) -> CarState {
        let (speed, percent_incline) = self
            .router
            .get_path()

View on GitHub (pinned to 0964f29315)