{"record":{"id":"fb508b5ee1f21313","repo":"a-b-street/abstreet","slug":"trying-to-make-a-crossing-state-from-to-at-something-s-very","errorCode":null,"errorMessage":"{} trying to make a crossing_state from {} to {} at {}. Something's very wrong","messagePattern":"(.+?) trying to make a crossing_state from (.+?) to (.+?) at (.+?)\\. Something's very wrong","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sim/src/mechanics/car.rs","lineNumber":43,"sourceCode":"    /// In reverse order -- most recently left is first. The sum length of these must be >=\n    /// vehicle.length.\n    pub last_steps: VecDeque<Traversable>,\n\n    /// Since lane over-taking isn't implemented yet, a vehicle tends to be stuck behind a slow\n    /// leader for a while. Avoid duplicate events.\n    pub wants_to_overtake: BTreeSet<CarID>,\n}\n\nimpl Car {\n    /// Assumes the current head of the path is the thing to cross.\n    pub fn crossing_state(&self, start_dist: Distance, start_time: Time, map: &Map) -> CarState {\n        let end_dist = if self.router.last_step() {\n            self.router.get_end_dist()\n        } else {\n            self.router.head().get_polyline(map).length()\n        };\n        if end_dist < start_dist {\n            panic!(\n                \"{} trying to make a crossing_state from {} to {} at {}. Something's very wrong\",\n                self.vehicle.id, start_dist, end_dist, start_time\n            );\n        }\n\n        let dist_int = DistanceInterval::new_driving(start_dist, end_dist);\n        self.crossing_state_with_end_dist(dist_int, start_time, map)\n    }\n\n    pub fn crossing_state_with_end_dist(\n        &self,\n        dist_int: DistanceInterval,\n        start_time: Time,\n        map: &Map,\n    ) -> CarState {\n        let (speed, percent_incline) = self\n            .router\n            .get_path()","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/a-b-street/abstreet/blob/0964f29315820c91b171b585eb51e300164e9197/sim/src/mechanics/car.rs#L25-L61","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Recompute or clamp car distances after applying map edits (recalculate paths/distances)","Reproduce with the printed vehicle id and inspect its router state at that time","Report/fix upstream — this indicates a simulation invariant bug, not bad user input"],"exampleFix":"// defensive clamp before constructing\nlet end_dist = end_dist.max(start_dist);\nlet dist_int = DistanceInterval::new_driving(start_dist, end_dist);","handlingStrategy":"try-catch","validationCode":"// before driving: ensure car distances fit the current (possibly edited) map\nassert!(car_dist <= map.get_l(lane).length());","typeGuard":null,"tryCatchPattern":"std::panic::catch_unwind(|| sim.step(&mut timer))\n    .map_err(|_| format!(\"sim crashed; see vehicle id in panic output\"));","preventionTips":["Recalculate pathfinding and car positions after applying edits to a live map","Avoid shortening lanes below existing car offsets; this is an internal invariant bug — report with the printed vehicle id"],"tags":["rust","panic","internal-invariant-violation","simulation"],"backgroundTag":"internal-invariant-violation","analyzedSha":"0964f29315820c91b171b585eb51e300164e9197","analyzedAt":"2026-09-13T18:02:03.421Z","contentChangedAt":"2026-09-13T18:02:03.421Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}