Last Updated: February 25, 2016
·
1.487K
· go3k

Android crash "Call to openGL API without a current context"

stackoverflow answer


From the GLSurfaceView documentation:

"There are situations where the EGL rendering context will be lost. This typically happens when device wakes up after going to sleep. When the EGL context is lost, all OpenGL resources (such as textures) that are associated with that context will be automatically deleted. In order to keep rendering correctly, a renderer must recreate any lost resources that it still needs. The onSurfaceCreated(GL10, EGLConfig) method is a convenient place to do this."

You need to be aware of lost OpenGL contexts, then reacquire the context and reload all OpenGL resources. It looks like your context is being lost when you display the full-screen file browser.


You are working on a cocos2d-x project?

You could find codes that resolve this problem in jni/xx/main.cpp:

Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit

But, you still will encounter this problem, for example, you call and show a fullscreen WebView dialog on the java side, and when you back to C++ thread then the crash happens. You should solve this problem by show this fullscreen WebView in a separate Activity, and when you close this Activity back to cocos2dActivity cocos2d-x will call the method up reinit the openGL context for you.