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 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,
|
||||||
|
Loading…
Reference in New Issue
Block a user