Skip to content

Commit 68c7410

Browse files
author
Comma Device
committed
do destroy images
1 parent 5ffcf4f commit 68c7410

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

selfdrive/ui/qt/widgets/cameraview.cc

+16-4
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ void CameraViewWidget::paintGL() {
235235

236236
#ifdef QCOM2
237237
glActiveTexture(GL_TEXTURE0);
238-
glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_images[frame->fd]);
238+
glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_images[frame->idx]);
239239
assert(glGetError() == GL_NO_ERROR);
240240
#else
241241
glPixelStorei(GL_UNPACK_ROW_LENGTH, stream_stride);
@@ -270,10 +270,15 @@ void CameraViewWidget::vipcConnected(VisionIpcClient *vipc_client) {
270270
stream_stride = vipc_client->buffers[0].stride;
271271

272272
#ifdef QCOM2
273-
EGLDisplay display = eglGetCurrentDisplay();
273+
egl_display = eglGetCurrentDisplay();
274+
275+
for (auto &pair : egl_images) {
276+
eglDestroyImageKHR(egl_display, pair.second);
277+
}
274278
egl_images.clear();
279+
275280
for (int i = 0; i < vipc_client->num_buffers; i++) { // import buffers into OpenGL
276-
int fd = vipc_client->buffers[i].fd;
281+
int fd = dup(vipc_client->buffers[i].fd); // eglDestroyImageKHR will close, so duplicate
277282
EGLint img_attrs[] = {
278283
EGL_WIDTH, (int)vipc_client->buffers[i].width,
279284
EGL_HEIGHT, (int)vipc_client->buffers[i].height,
@@ -286,7 +291,7 @@ void CameraViewWidget::vipcConnected(VisionIpcClient *vipc_client) {
286291
EGL_DMA_BUF_PLANE1_PITCH_EXT, (int)vipc_client->buffers[i].stride,
287292
EGL_NONE
288293
};
289-
egl_images[fd] = eglCreateImageKHR(display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, 0, img_attrs);
294+
egl_images[i] = eglCreateImageKHR(egl_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, 0, img_attrs);
290295
assert(eglGetError() == EGL_SUCCESS);
291296
}
292297
#else
@@ -341,4 +346,11 @@ void CameraViewWidget::vipcThread() {
341346
emit vipcThreadFrameReceived(buf, meta_main.frame_id);
342347
}
343348
}
349+
350+
#ifdef QCOM2
351+
for (auto &pair : egl_images) {
352+
eglDestroyImageKHR(egl_display, pair.second);
353+
}
354+
egl_images.clear();
355+
#endif
344356
}

selfdrive/ui/qt/widgets/cameraview.h

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class CameraViewWidget : public QOpenGLWidget, protected QOpenGLFunctions {
5757
QColor bg = QColor("#000000");
5858

5959
#ifdef QCOM2
60+
EGLDisplay egl_display;
6061
std::map<int, EGLImageKHR> egl_images;
6162
#endif
6263

0 commit comments

Comments
 (0)