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:
Dustin Carlino 2021-02-01 18:18:46 -08:00
parent 02b90741d6
commit 2bbc43b529

View File

@ -2,7 +2,7 @@ use std::collections::VecDeque;
use serde::{Deserialize, Serialize}; 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 map_model::{Direction, Map, Traversable};
use crate::{ use crate::{
@ -107,13 +107,16 @@ impl Car {
} }
if result.len() < 2 { if result.len() < 2 {
panic!( // Vehicles spawning at a border start with their front at literally 0 distance.
"{} at {} has front at {} of {:?}. Didn't even wind up with two points", // Usually by the time we first try to render, they've advanced at least a little.
self.vehicle.id, // But sometimes there's a race when we try to immediately draw them.
now, if let Ok((pl, _)) =
front, self.router
self.router.head() .head()
); .slice(Distance::ZERO, 2.0 * EPSILON_DIST, map)
{
result = pl.into_points();
}
} }
match PolyLine::new(result) { match PolyLine::new(result) {
Ok(pl) => pl, Ok(pl) => pl,