'How to fix the 0x3009 (EGL_BAD_MATCH) issue while invoking eglCreatePbufferSurface?

I use the createOffscreenSurface from grafika:

/**
 * Creates an off-screen surface.
 */
public void createOffscreenSurface(int width, int height) {
    if (mEGLSurface != EGL14.EGL_NO_SURFACE) {
        throw new IllegalStateException("surface already created");
    }
    mEGLSurface = mEglCore.createOffscreenSurface(width, height);
    mWidth = width;
    mHeight = height;
}

/**
 * Creates an EGL surface associated with an offscreen buffer.
 */
public EGLSurface createOffscreenSurface(int width, int height) {
    int[] surfaceAttribs = {
            EGL14.EGL_WIDTH, width,
            EGL14.EGL_HEIGHT, height,
            EGL14.EGL_NONE
    };
    EGLSurface eglSurface = EGL14.eglCreatePbufferSurface(mEGLDisplay, mEGLConfig,
            surfaceAttribs, 0);
    checkEglError("eglCreatePbufferSurface");
    if (eglSurface == null) {
        throw new RuntimeException("surface was null");
    }
    return eglSurface;
}

It works fine on some devices, but doesn't on other devices. The error msg is:

java.lang.RuntimeException: eglCreatePbufferSurface: EGL error: 0x3009

I also googled and got the following information:

  1. You need to setup the surface view with the appropriate pixel format for that phone, which is most likely PixelFormat.RGB565 (link)

  2. I'm pretty certain your surface is a different format to the actual display surface. (link)

However, i don't have ideas to fix it. Any suggestions ?



Solution 1:[1]

Use

new EglCore(EGL14.eglGetCurrentContext(), 0) 

to replace

new EglCore(newSharedContext, EglCore.FLAG_RECORDABLE);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jerikc XIONG