Android - Invalid GLSurfaceView

Hi All,

On Android (specifically Kindle HD) the OpenGL surface becomes not valid in certain scenarios and the following error occurs:

11-16 16:32:06.991: E/GLSurfaceView(6652): eglCreateWindowSurface
11-16 16:32:06.991: E/GLSurfaceView(6652): java.lang.IllegalArgumentException: Make sure the SurfaceView or associated SurfaceHolder has a valid Surface
11-16 16:32:06.991: E/GLSurfaceView(6652):  at com.google.android.gles_jni.EGLImpl._eglCreateWindowSurface(Native Method)
11-16 16:32:06.991: E/GLSurfaceView(6652):  at com.google.android.gles_jni.EGLImpl.eglCreateWindowSurface(EGLImpl.java:90)
11-16 16:32:06.991: E/GLSurfaceView(6652):  at android.opengl.GLSurfaceView$DefaultWindowSurfaceFactory.createWindowSurface(GLSurfaceView.java:798)
11-16 16:32:06.991: E/GLSurfaceView(6652):  at android.opengl.GLSurfaceView$EglHelper.createSurface(GLSurfaceView.java:1065)
11-16 16:32:06.991: E/GLSurfaceView(6652):  at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1433)
11-16 16:32:06.991: E/GLSurfaceView(6652):  at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)

On stackoverflow is a post that could explain this: [[http://stackoverflow.com/questions/12855103/eglcreatewindowsurface-fails-with-java-lang-illegalargumentexception]]

The best way to reproduce this bug is to launch another activity from your cocos2d activity while the SurfaceView is still initializing.

I have yet to try the solution on stackoverflow, but I’m wondering if anybody has a come across this and if there’s a better solution,
Thanks!

Hi Sheado,

I am facing this exact issue with the same exception and call stack. Have you implemented the solution you found on the stackoverflow link? If yes, did it work for you?

I found this issue on Android v4.0.4.

What’s the engine version?

The best way to reproduce this bug is to launch another activity from your cocos2d activity while the SurfaceView is still initializing.

Could you please paste some sample code?

Hey guys,

Sorry, I never seem to get notified when new messages come in.

I ended up removing the feature because I didn’t have time to deal with it.
I was using v2.2.1 and I was basically launching an AdMob interstitial ad onResume(). I think launching any activity while the GL surface is still initializing can cause this problem.

I have implemented google play services to our game. If the user does not have a google account signed in, google play services will switch to the standard google signin/signup menu. In the background the game crashes with the same call stack.

I am using cocos2d-x 2.2.5. We have seen the crash on Android 4.1.2, 4.2.2, 4.4

In Cocos2dxGLSurfaceView.java, we comment the codes to invoke super’s onPause()

@Override
	public void onPause() {
		this.queueEvent(new Runnable() {
			@Override
			public void run() {
				Cocos2dxGLSurfaceView.this.mCocos2dxRenderer.handleOnPause();
			}
		});
		this.setRenderMode(RENDERMODE_WHEN_DIRTY);
		//super.onPause();  // it is comment
	}

Comment this line to prevent gl context been destroyed. I am not sure if it causes the problem. Will you please uncomment it and have a try.