Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.

Commit 436c0b9

Browse files
committed
EGL: Correctly detect eglSwapBuffers errors, better teardown
1 parent 6251df8 commit 436c0b9

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

libswirl/utils/glinit/egl/egl.cpp

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ struct
1717
} egl_setup;
1818

1919

20-
static bool created_context;
21-
2220
bool 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

220218
void 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

Comments
 (0)