Crash on Android after onResume

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
Post Reply
CloudJin
Gnoblar
Posts: 13
Joined: Fri Jun 28, 2013 7:09 am

Crash on Android after onResume

Post by CloudJin »

I use OGRE 1.9RC1 in my game on Android. The game starts first is OK, but when I push the home button and return to the game, the game crash.
OGRE throw the exception swapbuffers failed, and the egl error is egl_bad_surface. I do not know why. The surface is valid.
btw: I use the JNI, not the native activity.
heres the error log.

Code: Select all

11-14 15:34:10.420: I/OGRE(9703): EGL error 0x300D in virtual void Ogre::EGLWindow::swapBuffers(bool) at line 320 in ..\..\..\RenderSystems\GLES\src\EGL\OgreEGLWindow.cpp 
11-14 15:34:10.420: E/OGRE(9703): OGRE EXCEPTION(3:RenderingAPIException): Fail to SwapBuffers in swapBuffers at ..\..\..\RenderSystems\GLES\src\EGL\OgreEGLWindow.cpp (line 323)
11-14 15:34:10.420: A/libc(9703): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 9703 (.geeeu.cloudapp)
Anyone helps?
Thanks
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Crash on Android after onResume

Post by c6burns »

I had this issue at one point around when v1-9-0RC1 got tagged, but I can't reproduce it now. My current environment is v1-9 tip, building with ndk-r8c toolchain, targetting platform android-10 armeabiv7.

Make sure the OgreJNI sample project exhibits the same behaviour.
CloudJin
Gnoblar
Posts: 13
Joined: Fri Jun 28, 2013 7:09 am

Re: Crash on Android after onResume

Post by CloudJin »

c6burns wrote:I had this issue at one point around when v1-9-0RC1 got tagged, but I can't reproduce it now. My current environment is v1-9 tip, building with ndk-r8c toolchain, targetting platform android-10 armeabiv7.

Make sure the OgreJNI sample project exhibits the same behaviour.
Thanks c6burns.
I used the OGRE1-9-0RC1 SDK, theres is not OGREjni sample but the native activity. And the native activity sample is OK.
I used the Android JNI, so I am not sure there are bugs in the OGRE1-9-0RC1 SDK or in my game.
Do you have any suggestions? Thanks.
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Crash on Android after onResume

Post by c6burns »

There's a JNI example if you build Ogre from source. What happens is when the app loses focus it calls _destroyInternalResources on the renderwindow, and when it gains focus it calls _createInternalResources again. This has to be done if you are using a SurfaceView since you are managing the EGL window. With a GLSurfaceView you manage EGL from the java side, so things would be different. Below is an excerpt from the OgreJNI sample ... initWindow is called on resume while termWindow is called on pause:

Code: Select all

    JNIEXPORT void JNICALL Java_org_ogre3d_android_OgreActivityJNI_initWindow(JNIEnv * env, jobject obj,  jobject surface)
	{
		if(surface)
		{
			ANativeWindow* nativeWnd = ANativeWindow_fromSurface(env, surface);
			if (nativeWnd && gRoot)
			{
				if (!gRenderWnd) 
				{
					Ogre::NameValuePairList opt;
					opt["externalWindowHandle"] = Ogre::StringConverter::toString((int)nativeWnd);
					gRenderWnd = Ogre::Root::getSingleton().createRenderWindow("OgreWindow", 0, 0, false, &opt);
					
					if(pSceneMgr == NULL) // create scenemanager, camera, viewport, etc in here
					{
					}						
				}
				else
				{
					static_cast<Ogre::AndroidEGLWindow*>(gRenderWnd)->_createInternalResources(nativeWnd, NULL);
				}                        
			}
		}
	}
	
    JNIEXPORT void JNICALL Java_org_ogre3d_android_OgreActivityJNI_termWindow(JNIEnv * env, jobject obj)
	{
		if(gRoot && gRenderWnd)
		{
			static_cast<Ogre::AndroidEGLWindow*>(gRenderWnd)->_destroyInternalResources();
		}
	}
CloudJin
Gnoblar
Posts: 13
Joined: Fri Jun 28, 2013 7:09 am

Re: Crash on Android after onResume

Post by CloudJin »

c6burns , I have done like the OgreJNI sample. I used the SurfaceView, initWindow is called on surfaceCreated, termWindow is called on surfaceDestroy, but it doesn't work.
Heres the code.

Code: Select all

public void surfaceCreated(SurfaceHolder holder) {
			Log.v("CloudApp.C", "surfaceCreated");
			if (holder.getSurface() != null
					&& holder.getSurface().isValid()) {
				lastSurface = holder.getSurface();
				//lastSurface = surfaceView.getHolder().getSurface();
				handler.post(initRunnable);
				Log.v("CloudApp.C", "post initRunnable in surfaceCreated()");
			}
		}

		public void surfaceDestroyed(SurfaceHolder holder) {
			Log.v("CloudApp.C", "surfaceDestroyed");
			if (initOGRE && wndCreate) {
				wndCreate = false;
				lastSurface = null;
				handler.post(new Runnable() {
					public void run() {
						OgreActivityJNI.termWindow();
					}
				});
			}
		}
I am crazy for this. I am sure the context is recreate, and the SurfaceView is valid. Why occurs the EGL error egl_bad_surface? or some others wrong?
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Crash on Android after onResume

Post by c6burns »

Well like I mentioned, I didn't resolve this through skill or awesome troubleshooting. I resolved my issue by updating ogre, changing ndk platform target, and using updated android dependencies (thanks Wolfman!). v1-9-0RC1 was tagged around 6 months ago now, I think. I can no longer reproduce the swap buffer issue in my environment. Long story short ... update some stuff and maybe it'll go away ;)
CloudJin
Gnoblar
Posts: 13
Joined: Fri Jun 28, 2013 7:09 am

Re: Crash on Android after onResume

Post by CloudJin »

Thanks c6burns.
Well I will update the OGRE to 1.9.0 rc2 to test.
Thanks again.
sarath_10
Gnoblar
Posts: 15
Joined: Tue Jun 11, 2013 10:38 am
x 1

Re: Crash on Android after onResume

Post by sarath_10 »

I am using Ogre 1.9 Stable release with OgreJNI and facing the same issue. I am calling _destroyInternalResources() in onPause and _createInternalResources() in onSurfaceCreated. After resuming the app i got this log

OGRE EXCEPTION(3:RenderingAPIException): Fail to SwapBuffers in swapBuffers at /Users/svanga/Projects/android-working/sinbad-ogre-dd30349ea667/RenderSystems/GLES2/src/EGL/OgreEGLWindow.cpp (line 161)

I am stuck on this as i cant create an android application with out handling these window/lifecycle events sucessfully. Any updates on this issue?
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Crash on Android after onResume

Post by c6burns »

Update to 1.9 head from mercurial. Pretty sure this issue is long gone.
sarath_10
Gnoblar
Posts: 15
Joined: Tue Jun 11, 2013 10:38 am
x 1

Re: Crash on Android after onResume

Post by sarath_10 »

@c6burns,
I have download the latest 1.9 branch code. I am still facing the same issue in OgreJNI sample provided.
The environment i used is
NDK : r8d
NDK API Level : 9
OS : Mac OS X
used cmake to build Ogre 1.9
sarath_10
Gnoblar
Posts: 15
Joined: Tue Jun 11, 2013 10:38 am
x 1

Re: Crash on Android after onResume

Post by sarath_10 »

I got rid of this issue by simply changing the android platform target to 10. Previously i was using android-14 as target. This is the only change i did.
Is there any dependency on android-10 or am i missing something? Strange fix though...
User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 99
Contact:

Re: Crash on Android after onResume

Post by Wolfmanfx »

No after android-10 the UI use the GPU to render and thats cause some problems. I am not sure how to fix it the problem is that the shaders and everything is regenerated but the driver do not give me any log output anymore.
User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 99
Contact:

Re: Crash on Android after onResume

Post by Wolfmanfx »

Post Reply