我制作了安卓相机应用程序,我需要使用 Pbuffer 来渲染捕获的 图像。
初始化OpenGL时遇到崩溃。
实际上当用户使用我的应用程序时会发生此崩溃,我从Fabric收到此消息
所以,我无法重现崩溃...并且不知道为什么会发生这种情况
也许我做错了什么。
请查看我的代码
private void initGL(int width, int height) {
egl10 = (EGL10) EGLContext.getEGL();
eglDisplay = egl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
if (eglDisplay == EGL10.EGL_NO_DISPLAY) {
throw new RuntimeException("eglGetDisplay failed " +
android.opengl.GLUtils.getEGLErrorString(egl10.eglGetError()));
}
int[] version = new int[2];
if (!egl10.eglInitialize(eglDisplay, version)) {
throw new RuntimeException("eglInitialize failed " +
android.opengl.GLUtils.getEGLErrorString(egl10.eglGetError()));
}
int[] configsCount = new int[1];
EGLConfig[] configs = new EGLConfig[1];
int[] configSpec = {
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL10.EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL10.EGL_RED_SIZE, 8,
EGL10.EGL_GREEN_SIZE, 8,
EGL10.EGL_BLUE_SIZE, 8,
EGL10.EGL_ALPHA_SIZE, 8,
EGL10.EGL_DEPTH_SIZE, 0,
EGL10.EGL_STENCIL_SIZE, 0,
EGL10.EGL_NONE
};
EGLConfig eglConfig = null;
if (!egl10.eglChooseConfig(eglDisplay, configSpec, configs, 1, configsCount)) {
throw new IllegalArgumentException("eglChooseConfig failed " +
android.opengl.GLUtils.getEGLErrorString(egl10.eglGetError()));
} else if (configsCount[0] > 0) {
eglConfig = configs[0];
}
if (eglConfig == null) {
throw new RuntimeException("eglConfig not initialized");
}
int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE};
eglContext = egl10.eglCreateContext(eglDisplay, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
int[] surfaceAttr = {
EGL10.EGL_WIDTH, width,
EGL10.EGL_HEIGHT, height,
EGL10.EGL_NONE
};
eglSurface = egl10.eglCreatePbufferSurface(eglDisplay, eglConfig, surfaceAttr);
if (eglSurface == null || eglSurface == EGL10.EGL_NO_SURFACE) {
throw new RuntimeException("eglCreatePbufferSurface failed " +
android.opengl.GLUtils.getEGLErrorString(egl10.eglGetError()));
}
if (!egl10.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
throw new RuntimeException("eglMakeCurrent failed " +
android.opengl.GLUtils.getEGLErrorString(egl10.eglGetError()));
}
}
这是错误梅萨
Fatal Exception: java.lang.RuntimeException: eglCreatePbufferSurface failed EGL_BAD_ALLOC
at com.teambartender3.filters.FilterableCamera.FCameraCapture.initGL(FCameraCapture.java:307)
at com.teambartender3.filters.FilterableCamera.FCameraCapture.access$200(FCameraCapture.java:48)
at com.teambartender3.filters.FilterableCamera.FCameraCapture$1.run(FCameraCapture.java:141)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.os.HandlerThread.run(HandlerThread.java:61)
如果你想查看我代码的完整版本,你可以访问我的GitHub Repo
...规范说...
https://www.khronos.org/registry/EGL/sdk/docs/man/html/eglCreatePbufferSurface.xhtml
如果没有足够的资源来生成
EGL_BAD_ALLOC
分配新曲面。
基本上,您没有正常处理内存不足的情况。