Created
January 21, 2013 12:56
-
-
Save wvdschel/4585850 to your computer and use it in GitHub Desktop.
Crashes on line 31, EGL_BAD_ALLOC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private boolean initGL(SurfaceHolder surfaceHolder) { | |
mEgl = (EGL10) EGLContext.getEGL(); | |
mEglDisplay = mEgl.eglGetDisplay(EGL_DEFAULT_DISPLAY); | |
if (mEglDisplay == EGL_NO_DISPLAY) { | |
throw new RuntimeException("eglGetDisplay failed " + | |
GLUtils.getEGLErrorString(mEgl.eglGetError())); | |
} | |
int[] version = new int[2]; | |
if (!mEgl.eglInitialize(mEglDisplay, version)) { | |
throw new RuntimeException("eglInitialize failed " + | |
GLUtils.getEGLErrorString(mEgl.eglGetError())); | |
} | |
mEglConfig = chooseEglConfig(); | |
if (mEglConfig == null) { | |
throw new RuntimeException("eglConfig not initialized"); | |
} | |
mEglContext = createContext(mEgl, mEglDisplay, mEglConfig); | |
mEglSurface = mEgl.eglCreateWindowSurface(mEglDisplay, mEglConfig, surfaceHolder, null); | |
if (mEglSurface == null || mEglSurface == EGL_NO_SURFACE) { | |
int error = mEgl.eglGetError(); | |
if (error == EGL_BAD_NATIVE_WINDOW) { | |
Log.e(GL_LOG_TAG, "createWindowSurface returned EGL_BAD_NATIVE_WINDOW."); | |
return false; | |
} | |
throw new RuntimeException("createWindowSurface failed " + | |
GLUtils.getEGLErrorString(error)); | |
} | |
if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) { | |
throw new RuntimeException("eglMakeCurrent failed " + | |
GLUtils.getEGLErrorString(mEgl.eglGetError())); | |
} | |
mGL = mEglContext.getGL(); | |
return true; | |
} | |
EGLContext createContext(EGL10 egl, EGLDisplay eglDisplay, EGLConfig eglConfig) { | |
int[] attrib_list = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; | |
return egl.eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT, attrib_list); | |
} | |
private EGLConfig chooseEglConfig() { | |
int[] configsCount = new int[1]; | |
EGLConfig[] configs = new EGLConfig[1]; | |
int[] configSpec = getConfig(); | |
if (!mEgl.eglChooseConfig(mEglDisplay, configSpec, configs, 1, configsCount)) { | |
throw new IllegalArgumentException("eglChooseConfig failed " + | |
GLUtils.getEGLErrorString(mEgl.eglGetError())); | |
} else if (configsCount[0] > 0) { | |
return configs[0]; | |
} | |
return null; | |
} | |
private int[] getConfig() { | |
return new int[] { | |
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | |
EGL_RED_SIZE, 8, | |
EGL_GREEN_SIZE, 8, | |
EGL_BLUE_SIZE, 8, | |
EGL_ALPHA_SIZE, 0, | |
EGL_DEPTH_SIZE, 0, | |
EGL_STENCIL_SIZE, 0, | |
EGL_CONFIG_CAVEAT, EGL_NONE, | |
EGL_NONE | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment