From a64b17b680679ccbc4013f068e6d35fcb8afdf62 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Tue, 9 Jul 2024 22:16:30 -0400 Subject: [PATCH] fix division by 0 and negative values --- selfdrive/ui/qt/onroad/annotated_camera.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/selfdrive/ui/qt/onroad/annotated_camera.cc b/selfdrive/ui/qt/onroad/annotated_camera.cc index 59624c4f46..a99517d33d 100644 --- a/selfdrive/ui/qt/onroad/annotated_camera.cc +++ b/selfdrive/ui/qt/onroad/annotated_camera.cc @@ -1535,7 +1535,8 @@ void AnnotatedCameraWidget::drawLead(QPainter &painter, const cereal::RadarState } if (chevron_data == 3 || chevron_data == 4) { position = (chevron_data == 3) ? 0 : 2; - chevron_text[position].append(QString::number(d_rel / v_ego, 'f', 1) + " " + "s"); + float val = (v_ego != 0.0f) ? std::max(0.0f, d_rel / v_ego) : 0.0f; + chevron_text[position].append(QString::number(val, 'f', 1) + " " + "s"); } int str_w = 200; // Width of the text box, might need adjustment