Quantcast
Channel: cocos2d-x - Cocos Forums
Viewing all articles
Browse latest Browse all 2748

Cocos2dx Android exception thrown on devices not supporting egl 3.0

$
0
0

@VladCioaba wrote:

The problem is in createContext ( Cocos2dxActiviti.java )

if the context fails to initialize egl.eglCreateContext( .. ) will NOT return a NULL pointer. The return will be EGL10.EGL_NO_CONTEXT witch is a valid pointer. The application will crash later because the valid context was not created.

This is a possible fix for this issue:

public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {

            // create GL ES 3 context first,
            // if failed, then try to create GL ES 2 context

            int[] attributes = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL10.EGL_NONE };
            // attempt to create a OpenGL ES 3.0 context
            EGLContext context = egl.eglCreateContext(
                display, eglConfig, EGL10.EGL_NO_CONTEXT, attributes);

            if (context == EGL10.EGL_NO_CONTEXT) {
                attributes = new int[] {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
                context = egl.eglCreateContext(
                    display, eglConfig, EGL10.EGL_NO_CONTEXT, attributes);
            }

            if (context == EGL10.EGL_NO_CONTEXT)  {
                Log.e(DEVICE_POLICY_SERVICE, "Unable to create eagl context!");
            }

        return context;
    }

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 2748

Latest Images

Trending Articles



Latest Images