diff --git a/gfx/context/bbqnx_ctx.c b/gfx/context/bbqnx_ctx.c index 7e19ef9a14..a180853d6f 100644 --- a/gfx/context/bbqnx_ctx.c +++ b/gfx/context/bbqnx_ctx.c @@ -61,17 +61,31 @@ static void gfx_ctx_qnx_set_swap_interval(void *data, unsigned interval) static void gfx_ctx_qnx_destroy(void *data) { (void)data; - eglMakeCurrent(g_egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - eglDestroyContext(g_egl_dpy, g_egl_ctx); - eglDestroySurface(g_egl_dpy, g_egl_surf); - eglTerminate(g_egl_dpy); - //eglReleaseThread(); - g_egl_dpy = EGL_NO_DISPLAY; - g_egl_surf = EGL_NO_SURFACE; - g_egl_ctx = EGL_NO_CONTEXT; - g_config = 0; - g_resize = false; + if (g_egl_dpy) + { + if (g_egl_ctx) + { + eglMakeCurrent(g_egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + eglDestroyContext(g_egl_dpy, g_egl_ctx); + } + + if (g_egl_hw_ctx) + eglDestroyContext(g_egl_dpy, g_egl_hw_ctx); + + if (g_egl_surf) + eglDestroySurface(g_egl_dpy, g_egl_surf); + eglTerminate(g_egl_dpy); + } + + // Be as careful as possible in deinit. + + g_egl_ctx = NULL; + g_egl_hw_ctx = NULL; + g_egl_surf = NULL; + g_egl_dpy = NULL; + g_config = 0; + g_resize = false; } static void gfx_ctx_qnx_get_video_size(void *data, unsigned *width, unsigned *height)