Skip to content

Commit daa7304

Browse files
committed
bail out of init early if an error is encountered for maximum correctness
call eglTerminate before init returns. if another init on the same OS thread has already created a context, eglTerminate is a no-op until the context is destroyed. otherwise, this allows scenarios where a program that imports x/mobile/gl might want to call eglInitialize on a different display.
1 parent 865f9d6 commit daa7304

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

gl/egl.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import "C"
1414
func init() {
1515
display := C.eglGetDisplay(C.EGL_DEFAULT_DISPLAY)
1616

17-
C.eglInitialize(display, nil, nil)
17+
if C.eglInitialize(display, nil, nil) == C.EGL_FALSE {
18+
return
19+
}
20+
defer C.eglTerminate(display)
1821

1922
attributes := []C.EGLint{
2023
C.EGL_RED_SIZE, 1,
@@ -27,7 +30,9 @@ func init() {
2730
config C.EGLConfig
2831
count C.EGLint
2932
)
30-
C.eglChooseConfig(display, &attributes[0], &config, 1, &count)
33+
if C.eglChooseConfig(display, &attributes[0], &config, 1, &count) == C.EGL_FALSE {
34+
return
35+
}
3136

3237
C.eglBindAPI(C.EGL_OPENGL_ES_API)
3338

0 commit comments

Comments
 (0)