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 » Thu Nov 14, 2013 8:52 am

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
0 x

User avatar
c6burns
Beholder
Posts: 1511
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines

Re: Crash on Android after onResume

Post by c6burns » Thu Nov 14, 2013 9:24 am

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.
0 x

CloudJin
Gnoblar
Posts: 13
Joined: Fri Jun 28, 2013 7:09 am

Re: Crash on Android after onResume

Post by CloudJin » Thu Nov 14, 2013 10:04 am

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.
0 x

User avatar
c6burns
Beholder
Posts: 1511
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines

Re: Crash on Android after onResume

Post by c6burns » Thu Nov 14, 2013 6:00 pm

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();
		}
	}
0 x

CloudJin
Gnoblar
Posts: 13
Joined: Fri Jun 28, 2013 7:09 am

Re: Crash on Android after onResume

Post by CloudJin » Fri Nov 15, 2013 2:19 am

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?
0 x

User avatar
c6burns
Beholder
Posts: 1511
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines

Re: Crash on Android after onResume

Post by c6burns » Fri Nov 15, 2013 2:27 am

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 ;)
0 x

CloudJin
Gnoblar
Posts: 13
Joined: Fri Jun 28, 2013 7:09 am

Re: Crash on Android after onResume

Post by CloudJin » Fri Nov 15, 2013 3:34 am

Thanks c6burns.
Well I will update the OGRE to 1.9.0 rc2 to test.
Thanks again.
0 x

sarath_10
Gnoblar
Posts: 15
Joined: Tue Jun 11, 2013 10:38 am

Re: Crash on Android after onResume

Post by sarath_10 » Tue Jan 28, 2014 8:08 pm

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?
0 x

User avatar
c6burns
Beholder
Posts: 1511
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines

Re: Crash on Android after onResume

Post by c6burns » Wed Jan 29, 2014 12:14 am

Update to 1.9 head from mercurial. Pretty sure this issue is long gone.
0 x

sarath_10
Gnoblar
Posts: 15
Joined: Tue Jun 11, 2013 10:38 am

Re: Crash on Android after onResume

Post by sarath_10 » Thu Jan 30, 2014 7:00 am

@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
0 x

sarath_10
Gnoblar
Posts: 15
Joined: Tue Jun 11, 2013 10:38 am

Re: Crash on Android after onResume

Post by sarath_10 » Sat Feb 01, 2014 6:16 pm

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...
0 x

User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 1
Contact:

Re: Crash on Android after onResume

Post by Wolfmanfx » Sat Feb 01, 2014 7:00 pm

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.
0 x

User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 1
Contact:

Re: Crash on Android after onResume

Post by Wolfmanfx » Mon Mar 03, 2014 10:42 am

0 x

Post Reply