mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 15:33:44 +03:00
Avoid crashing when we try to draw a vehicle that's literally just
spawned at a border and hasn't advanced at all.
This commit is contained in:
parent
02b90741d6
commit
2bbc43b529
@ -2,7 +2,7 @@ use std::collections::VecDeque;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use geom::{Distance, Duration, PolyLine, Time};
|
||||
use geom::{Distance, Duration, PolyLine, Time, EPSILON_DIST};
|
||||
use map_model::{Direction, Map, Traversable};
|
||||
|
||||
use crate::{
|
||||
@ -107,13 +107,16 @@ impl Car {
|
||||
}
|
||||
|
||||
if result.len() < 2 {
|
||||
panic!(
|
||||
"{} at {} has front at {} of {:?}. Didn't even wind up with two points",
|
||||
self.vehicle.id,
|
||||
now,
|
||||
front,
|
||||
self.router.head()
|
||||
);
|
||||
// Vehicles spawning at a border start with their front at literally 0 distance.
|
||||
// Usually by the time we first try to render, they've advanced at least a little.
|
||||
// But sometimes there's a race when we try to immediately draw them.
|
||||
if let Ok((pl, _)) =
|
||||
self.router
|
||||
.head()
|
||||
.slice(Distance::ZERO, 2.0 * EPSILON_DIST, map)
|
||||
{
|
||||
result = pl.into_points();
|
||||
}
|
||||
}
|
||||
match PolyLine::new(result) {
|
||||
Ok(pl) => pl,
|
||||
|
Loading…
Reference in New Issue
Block a user