Arm Community
Arm Community
  • Site
  • User
  • Site
  • Search
  • User
  • Groups
    • Arm Research
    • DesignStart
    • Education Hub
    • Innovation
    • Open Source Software and Platforms
  • Forums
    • AI and ML forum
    • Architectures and Processors forum
    • Arm Development Platforms forum
    • Arm Development Studio forum
    • Arm Virtual Hardware forum
    • Automotive forum
    • Compilers and Libraries forum
    • Graphics, Gaming, and VR forum
    • High Performance Computing (HPC) forum
    • Infrastructure Solutions forum
    • Internet of Things (IoT) forum
    • Keil forum
    • Morello Forum
    • Operating Systems forum
    • SoC Design and Simulation forum
    • 中文社区论区
  • Blogs
    • AI and ML blog
    • Announcements
    • Architectures and Processors blog
    • Automotive blog
    • Graphics, Gaming, and VR blog
    • High Performance Computing (HPC) blog
    • Infrastructure Solutions blog
    • Innovation blog
    • Internet of Things (IoT) blog
    • Mobile blog
    • Operating Systems blog
    • Research Articles
    • SoC Design and Simulation blog
    • Smart Homes
    • Tools, Software and IDEs blog
    • Works on Arm blog
    • 中文社区博客
  • Support
    • Open a support case
    • Documentation
    • Downloads
    • Training
    • Arm Approved program
    • Arm Design Reviews
  • Community Help
  • More
  • Cancel
Arm Community blogs
Arm Community blogs
Operating Systems blog Check your context if glCreateShader returns 0 and GL_INVALID_OPERATION
  • Blogs
  • Mentions
  • Sub-Groups
  • Tags
  • Jump...
  • Cancel
More blogs in Arm Community blogs
  • AI and ML blog

  • Announcements

  • Architectures and Processors blog

  • Automotive blog

  • Embedded blog

  • Graphics, Gaming, and VR blog

  • High Performance Computing (HPC) blog

  • Infrastructure Solutions blog

  • Internet of Things (IoT) blog

  • Operating Systems blog

  • SoC Design and Simulation blog

  • Tools, Software and IDEs blog

Tags
  • android ndk
  • glcreateshader
  • error
  • opengl es2
  • opengl_es_2.0
  • native
  • error_resolution
  • first_android_native_application
  • gl_invalid_operation
  • OpenGL
  • native-library
  • egl_context_client_version
Actions
  • RSS
  • More
  • Cancel
Related blog posts
Related forum threads

Check your context if glCreateShader returns 0 and GL_INVALID_OPERATION

Myy
Myy
May 22, 2016

I passed half a day hunting weird bugs on Android's Native Activity.

The one I'll talk about here is if glCreateShader suddenly returns 0 and glError sends you back 0x502 (GL_INVALID_OPERATION - 1282).

I had a lot of trouble finding a working solution for this problem, so here it is, for the record.

The solution that worked for me

Pass a GLEnum array[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE } as the last parameter of your eglCreateContext call, in order to be sure that EGL will set up an OpenGL ES 2.0 context.

Defining { ..., EGL_CONFORMANT, EGL_OPENGL_ES2_BIT, ... } in your configuration attributes list is NOT enough. I guess that a conformant OpenGL ES 2.0 configuration can still be used for OpenGL ES 1.0.

    const EGLint attribs[] = {
      EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
      EGL_BLUE_SIZE, 8,
      EGL_GREEN_SIZE, 8,
      EGL_RED_SIZE, 8,
      EGL_CONFORMANT, EGL_OPENGL_ES2_BIT,
      EGL_NONE
    };

    const EGLint GiveMeGLES2[] = {
      EGL_CONTEXT_CLIENT_VERSION, 2,
      EGL_NONE
    };

    /* ... */

    eglChooseConfig(display, attribs, &config, 1, &numConfigs);

    eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);

    ANativeWindow_setBuffersGeometry(window, 0, 0, format);

    surface = eglCreateWindowSurface(display, config, window, NULL);
    context = eglCreateContext(display, config, NULL, GiveMeGLES2);

Passing EGL_CONTEXT_CLIENT_VERSION as the third parameter of eglQueryContext can tell you which OpenGL ES version your context was prepared for.

    GLuint v = 0;
    eglQueryContext(display, context, EGL_CONTEXT_CLIENT_VERSION, &v);

    __android_log_print(ANDROID_LOG_ERROR, LOGTAG, "Context prepared for OpenGL ES : %d", v);

Red herrings

Shader calls should be within a GL thread that is onSurfaceChanged(), onSurfaceCreated() or onDrawFrame(). (from StackOverflow)

This was not an issue. However, thanks to the BioniC team who was kind enough to implement the gettid system call.

You will need the following headers to get gettid working :

#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>

Example :

__android_log_print(ANDROID_LOG_ERROR, "native-insanity", "Thread ID : %d", gettid());

You can use this to log the id of the threads calling your different procedures, for comparison.

glCreateShader will return GL_INVALID_OPERATION if called between glBegin and glEnd. (from old OpenGL manuals)

Non-issue with OpenGL ES > 2.x since those calls are unavailable.

Note that the current Khronos manuals do not even mention this error.

It really took me a LOT of time to understand what went wrong with this, given the lack of documentation on this issue. I'd really appreciate if some website compiled all the potential issues you can have with OpenGL with potential solutions and hints.

Anonymous

Top Comments

  • Antares
    Offline Antares over 3 years ago +1
    Thank you so much for this solution. Had this problem and have been searching for a solution for 2 days until finding this one.
  • Jakub Duchniewicz
    Offline Jakub Duchniewicz over 1 year ago

    Thank you so much benevolent stranger. I was growing insane :)

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
  • Antares
    Offline Antares over 3 years ago

    Thank you so much for this solution. Have been searching for this solution for two days. Thanks again!

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
  • Antares
    Offline Antares over 3 years ago

    Thank you so much for this solution. Had this problem and have been searching for a solution for 2 days until finding this one.

    • Cancel
    • Up +1 Down
    • Reply
    • More
    • Cancel
Operating Systems blog
  • MongoDB performance on Arm Neoverse based AWS Graviton2 processors

    Julio Suarez
    Julio Suarez
    In this post, we show how the AWS Graviton2 based R6g achieves 117% higher throughput on MongoDB than the x86-based R5.
    • June 9, 2021
  • OCI Ampere A1 Compute instances can significantly reduce video encoding costs versus modern CPUs

    Steve Demski
    Steve Demski
    In this blog we show how OCI A1 instances provide leading performance per dollar for x264 video encoding.
    • May 25, 2021
  • Arm-based OCI Ampere A1 Compute instances beat the latest competition on NGINX

    Steve Demski
    Steve Demski
    In this blog we test the performance of OCI A1 Arm-based instances on NGINX Plus compared to competitive offerings.
    • May 25, 2021