From c7cc331df53a91df58d7e70c62f123d387a37d07 Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Wed, 17 Apr 2024 13:23:54 +0800 Subject: [PATCH] ui/map_eta: avoid divide by zero (#31962) old-commit-hash: 2bee28938ac2f50ec0d0e9f74f9f276a98c62f0d --- selfdrive/ui/qt/maps/map_eta.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/selfdrive/ui/qt/maps/map_eta.cc b/selfdrive/ui/qt/maps/map_eta.cc index 161844c618..0eb77e36ce 100644 --- a/selfdrive/ui/qt/maps/map_eta.cc +++ b/selfdrive/ui/qt/maps/map_eta.cc @@ -38,10 +38,13 @@ void MapETA::updateETA(float s, float s_typical, float d) { auto remaining = s < 3600 ? std::pair{QString::number(int(s / 60)), tr("min")} : std::pair{QString("%1:%2").arg((int)s / 3600).arg(((int)s % 3600) / 60, 2, 10, QLatin1Char('0')), tr("hr")}; QString color = "#25DA6E"; - if (s / s_typical > 1.5) - color = "#DA3025"; - else if (s / s_typical > 1.2) - color = "#DAA725"; + if (std::abs(s_typical) > 1e-5) { + if (s / s_typical > 1.5) { + color = "#DA3025"; + } else if (s / s_typical > 1.2) { + color = "#DAA725"; + } + } // Distance auto distance = map_format_distance(d, uiState()->scene.is_metric);