From 1e0ef417c32bcf29cdab9849f104336adae4a540 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Mon, 29 Nov 2021 15:49:41 -0800 Subject: [PATCH] UI: fix cameraview crash after going offroad in settings window (#23009) (#23068) Co-authored-by: Dean Lee --- selfdrive/ui/qt/widgets/cameraview.cc | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/selfdrive/ui/qt/widgets/cameraview.cc b/selfdrive/ui/qt/widgets/cameraview.cc index 1daabd7d1..6cc26a0ca 100644 --- a/selfdrive/ui/qt/widgets/cameraview.cc +++ b/selfdrive/ui/qt/widgets/cameraview.cc @@ -153,16 +153,21 @@ void CameraViewWidget::initializeGL() { void CameraViewWidget::showEvent(QShowEvent *event) { latest_frame = nullptr; - vipc_thread = new QThread(); - connect(vipc_thread, &QThread::started, [=]() { vipcThread(); }); - connect(vipc_thread, &QThread::finished, vipc_thread, &QObject::deleteLater); - vipc_thread->start(); + if (!vipc_thread) { + vipc_thread = new QThread(); + connect(vipc_thread, &QThread::started, [=]() { vipcThread(); }); + connect(vipc_thread, &QThread::finished, vipc_thread, &QObject::deleteLater); + vipc_thread->start(); + } } void CameraViewWidget::hideEvent(QHideEvent *event) { - vipc_thread->requestInterruption(); - vipc_thread->quit(); - vipc_thread->wait(); + if (vipc_thread) { + vipc_thread->requestInterruption(); + vipc_thread->quit(); + vipc_thread->wait(); + vipc_thread = nullptr; + } } void CameraViewWidget::updateFrameMat(int w, int h) {