From 9ae00d7bb241a4dd12024b2990c3bf5e3c289061 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Sun, 2 Mar 2025 21:24:06 +0800 Subject: [PATCH] fix(main): destroy temp egl context on init --- src/main/cpp/egl/loader.cpp | 21 ++++++++++++++++++--- src/main/cpp/egl/loader.h | 1 + src/main/cpp/main.cpp | 2 ++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/cpp/egl/loader.cpp b/src/main/cpp/egl/loader.cpp index 6896edc..105239f 100644 --- a/src/main/cpp/egl/loader.cpp +++ b/src/main/cpp/egl/loader.cpp @@ -12,10 +12,12 @@ #define DEBUG 0 + +static EGLDisplay eglDisplay = EGL_NO_DISPLAY; +static EGLSurface eglSurface = EGL_NO_SURFACE; +static EGLContext eglContext = EGL_NO_CONTEXT; + void init_target_egl() { - EGLDisplay eglDisplay = EGL_NO_DISPLAY; - EGLSurface eglSurface = EGL_NO_SURFACE; - EGLContext eglContext = EGL_NO_CONTEXT; LOAD_EGL(eglGetProcAddress); LOAD_EGL(eglBindAPI); @@ -115,4 +117,17 @@ cleanup: egl_eglTerminate(eglDisplay); } LOG_E("EGL initialization failed"); +} + +void destroy_temp_egl_ctx() { + LOAD_EGL(eglDestroySurface); + LOAD_EGL(eglDestroyContext); + LOAD_EGL(eglMakeCurrent); + LOAD_EGL(eglTerminate); + + egl_eglMakeCurrent(eglDisplay, 0, 0, EGL_NO_CONTEXT); + egl_eglDestroySurface(eglDisplay, eglSurface); + egl_eglDestroyContext(eglDisplay, eglContext); + + egl_eglTerminate(eglDisplay); } \ No newline at end of file diff --git a/src/main/cpp/egl/loader.h b/src/main/cpp/egl/loader.h index d76d736..225456a 100644 --- a/src/main/cpp/egl/loader.h +++ b/src/main/cpp/egl/loader.h @@ -173,6 +173,7 @@ EGLBoolean mglues_eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface rea */ void init_target_egl(); +void destroy_temp_egl_ctx(); #ifdef __cplusplus diff --git a/src/main/cpp/main.cpp b/src/main/cpp/main.cpp index f3fe138..399aaf5 100644 --- a/src/main/cpp/main.cpp +++ b/src/main/cpp/main.cpp @@ -85,5 +85,7 @@ void proc_init() { init_perfetto(); #endif + // Cleanup + destroy_temp_egl_ctx(); g_initialized = 1; }