1

I really need someone help to understand the issue that I am facing. I am trying to get the GPU information from the below lines:

renderer = GLES20.glGetString(GLES20.GL_RENDERER);

vendor = GLES20.glGetString(GLES20.GL_VENDOR);

version = GLES20.glGetString(GLES20.GL_VERSION);

If I execute these lines from "OnCreate" method of an Activity I am receiving the error "E/libEGL(4380): call to OpenGL ES API with no current context (logged once per thread)" in the logcat and empty value is returned.

However If I execute these lines through button Click I am getting results.

Can you someone help to me identify what mistake I am doing or is there any other thing I need to learn on this?

How do I get the result even If I execute from the onCreate Method?

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Dina
  • 23
  • 1
  • 1
  • 5

1 Answers1

2

The problem is exactly what the error message tells you: You're trying to make OpenGL calls (glGetString) without having a current OpenGL context. OpenGL calls require a current context in the thread you're making the calls from.

The typical use of OpenGL includes using a GLSurfaceView, which takes care of creating a context, and making it current. If you do need to make OpenGL calls from other places in the code, you need to take care of creating an OpenGL context yourself. This is done using the EGL10 or EGL14 class. You can find complete code in my answer here: GLES10.glGetIntegerv returns 0 in Lollipop only.

Why it works from the button click handler is less clear. It seems like at least some versions of Android have a "stray" OpenGL context that happens to be current under certain circumstances. I wouldn't count on that working consistently, though. For example, as you can see in the question liked above, some people got burnt by relying on this when it stopped working on Lollipop.

Community
  • 1
  • 1
Reto Koradi
  • 53,228
  • 8
  • 93
  • 133