From 5ada7c007bae0fa6d57ae56589ded68498b0721b Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Thu, 14 Dec 2023 12:18:45 +0800 Subject: [PATCH] ui: destroy egl_images in main thread (#30253) * call eglDestroyImageKHR in ui thread * assert old-commit-hash: dbda641cee9c8b5218518ffd6589599c8f641faf --- selfdrive/ui/qt/widgets/cameraview.cc | 22 +++++++++++++--------- selfdrive/ui/qt/widgets/cameraview.h | 1 - 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/selfdrive/ui/qt/widgets/cameraview.cc b/selfdrive/ui/qt/widgets/cameraview.cc index edf7b5990b..7b1f2f1d24 100644 --- a/selfdrive/ui/qt/widgets/cameraview.cc +++ b/selfdrive/ui/qt/widgets/cameraview.cc @@ -187,12 +187,23 @@ void CameraWidget::showEvent(QShowEvent *event) { } void CameraWidget::stopVipcThread() { + makeCurrent(); if (vipc_thread) { vipc_thread->requestInterruption(); vipc_thread->quit(); vipc_thread->wait(); vipc_thread = nullptr; } + +#ifdef QCOM2 + EGLDisplay egl_display = eglGetCurrentDisplay(); + assert(egl_display != EGL_NO_DISPLAY); + for (auto &pair : egl_images) { + eglDestroyImageKHR(egl_display, pair.second); + assert(eglGetError() == EGL_SUCCESS); + } + egl_images.clear(); +#endif } void CameraWidget::availableStreamsUpdated(std::set streams) { @@ -323,8 +334,8 @@ void CameraWidget::vipcConnected(VisionIpcClient *vipc_client) { stream_stride = vipc_client->buffers[0].stride; #ifdef QCOM2 - egl_display = eglGetCurrentDisplay(); - + EGLDisplay egl_display = eglGetCurrentDisplay(); + assert(egl_display != EGL_NO_DISPLAY); for (auto &pair : egl_images) { eglDestroyImageKHR(egl_display, pair.second); } @@ -415,13 +426,6 @@ void CameraWidget::vipcThread() { } } } - -#ifdef QCOM2 - for (auto &pair : egl_images) { - eglDestroyImageKHR(egl_display, pair.second); - } - egl_images.clear(); -#endif } void CameraWidget::clearFrames() { diff --git a/selfdrive/ui/qt/widgets/cameraview.h b/selfdrive/ui/qt/widgets/cameraview.h index fcd5b1b18f..c97038cf43 100644 --- a/selfdrive/ui/qt/widgets/cameraview.h +++ b/selfdrive/ui/qt/widgets/cameraview.h @@ -70,7 +70,6 @@ protected: QColor bg = QColor("#000000"); #ifdef QCOM2 - EGLDisplay egl_display; std::map egl_images; #endif