Reputation: 65
I've written a program that creates a window on WINCE and uses EGL to create the drawing surface and context. When this program quits, I have the following clean up routine:
eglMakeCurrent(m_eglDisplay,EGL_NO_SURFACE,EGL_NO_SURFACE,m_eglContext);
eglDestroyContext(m_eglDisplay,m_eglContext);
glDeleteProgram(m_eglProgramObject);
glReleaseShaderCompiler();
delete m_eglDisplay;
delete m_eglSurface;
delete m_eglContext;
delete m_eglConfig;
If I don't restart the target system, eventually the opening and closing of this program causes this following line to fail:
m_eglContext = eglCreateContext(m_eglDisplay,m_eglConfig,EGL_NO_CONTEXT,arrContextAttrib);
With EGL error 12291 which apparently means EGL_BAD_ALLOC. I assume there's some memory related to EGL that isn't being deleted properly every time the program exits but don't know what this could possibly be. Any suggestions?
Upvotes: 2
Views: 3160
Reputation: 155
To properly release your EGL and OpenGL 2.0 resources properly you have to make do following;
glDeleteProgram(m_eglProgramObject);
Delete any other GL resources created. For example textures, framebuffer, vertexbuffer, pixelbuffers etc
After this you have to do a eglmakecurrent with null surfaces and context. This will de-associate your EGLContext with the current thread (TLS)
eglMakeCurrent(m_eglDisplay,EGL_NO_SURFACE,EGL_NO_SURFACE, EGL_NO_CONTEXT );
After this you have to release all the EGLResources created:
eglDestroySurface(m_eglDisplay,m_eglSurface);
eglDestroyContext(m_eglDisplay,m_eglContext);
In the end do the eglTerminate:
eglTerminate(m_eglDisplay);
If you have also created any platform window object, For example XDisplay for X11, wl_display for Wayland or AWindow for Android. You have to delete/destroy that also.
I hope it helps.
Upvotes: 2