1717} egl_setup;
1818
1919
20- static bool created_context;
21-
2220bool egl_MakeCurrent ()
2321{
2422 if (egl_setup.surface == EGL_NO_SURFACE || egl_setup.context == EGL_NO_CONTEXT)
@@ -163,7 +161,6 @@ bool egl_Init(void* wind, void* disp)
163161 if (!load_gles_symbols ())
164162 die (" Failed to load symbols" );
165163 }
166- created_context = true ;
167164 }
168165 else if (glGetError == NULL )
169166 {
@@ -204,7 +201,8 @@ bool egl_Swap()
204201
205202 bool rv = true ;
206203
207- if (status != GL_TRUE && status != GL_FALSE) {
204+ if (status != GL_TRUE) {
205+ printf (" EGL: eglSwapBuffers failed. Error: %d\n " , eglGetError ());
208206 rv = false ;
209207 }
210208
@@ -219,26 +217,29 @@ bool egl_Swap()
219217
220218void egl_Term ()
221219{
222- if (!created_context)
223- return ;
224- created_context = false ;
225- eglMakeCurrent (egl_setup.display , NULL , NULL , EGL_NO_CONTEXT);
220+
221+ if (egl_setup.display != EGL_NO_DISPLAY) {
222+ eglMakeCurrent (egl_setup.display , EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
226223#if HOST_OS == OS_WINDOWS
227- ReleaseDC ((HWND)egl_setup.native_wind , (HDC)egl_setup.native_disp );
224+ ReleaseDC ((HWND)egl_setup.native_wind , (HDC)egl_setup.native_disp );
228225#else
229- if (egl_setup.context != NULL )
230- eglDestroyContext (egl_setup.display , egl_setup.context );
231- if (egl_setup.surface != NULL )
232- eglDestroySurface (egl_setup.display , egl_setup.surface );
226+ if (egl_setup.context != NULL )
227+ eglDestroyContext (egl_setup.display , egl_setup.context );
228+ if (egl_setup.surface != NULL )
229+ eglDestroySurface (egl_setup.display , egl_setup.surface );
233230#ifdef TARGET_PANDORA
234- if (egl_setup.display )
235- eglTerminate (egl_setup.display );
236- if (fbdev >= 0 )
237- close (fbdev);
238- fbdev = -1 ;
231+ if (egl_setup.display )
232+ eglTerminate (egl_setup.display );
233+ if (fbdev >= 0 )
234+ close (fbdev);
235+ fbdev = -1 ;
239236#endif
240- #endif // !OS_WINDOWS
241- egl_setup.context = EGL_NO_CONTEXT;
242- egl_setup.surface = EGL_NO_SURFACE;
243- egl_setup.display = EGL_NO_DISPLAY;
237+ #endif // !OS_WINDOWS
238+ eglTerminate (egl_setup.display );
239+
240+ egl_setup.context = EGL_NO_CONTEXT;
241+ egl_setup.surface = EGL_NO_SURFACE;
242+ egl_setup.display = EGL_NO_DISPLAY;
243+
244+ }
244245}
0 commit comments