[SOLVED]EglSwapBuffers exception on Android

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

[SOLVED]EglSwapBuffers exception on Android

Post by CloudJin »

Thank you for reading.
There is a confusing issue in my game. When I show the Android dialog and close the dialog, Ogre can't render anything and throw the exception.

Code: Select all

11-28 16:41:07.710: I/OGRE(13565): EGL error 0x3006 in virtual void Ogre::EGLWindow::swapBuffers() at line 320 in jni/../../../RenderSystems/GLES/src/EGL/OgreEGLWindow.cpp 
11-28 16:41:07.710: E/OGRE(13565): OGRE EXCEPTION(3:RenderingAPIException): Fail to SwapBuffers in swapBuffers at jni/../../../RenderSystems/GLES/src/EGL/OgreEGLWindow.cpp (line 323)
I just know the Activity lost the focus while showing the dialog.
My question is what happened after showing and closing the dialog in Ogre? Or do I need to do something else?
Thanks.
Last edited by CloudJin on Wed Dec 04, 2013 9:52 am, edited 1 time in total.
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: EglSwapBuffers exception on Android

Post by Wolfmanfx »

Which android target do you use? (4.x?)
CloudJin
Gnoblar
Posts: 13
Joined: Fri Jun 28, 2013 7:09 am

Re: EglSwapBuffers exception on Android

Post by CloudJin »

Wolfmanfx wrote:Which android target do you use? (4.x?)
Thanks for replying, Wolfmanfx.
I use android 4.1.1.
BTW: I use the Android JNI, not the native activity.
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: EglSwapBuffers exception on Android

Post by Wolfmanfx »

Try tp target android-10 (2.3.3) and tell if thats solve the problem?
CloudJin
Gnoblar
Posts: 13
Joined: Fri Jun 28, 2013 7:09 am

Re: EglSwapBuffers exception on Android

Post by CloudJin »

I target the Android-10, but it does not work.
I found if I call SurfaceView.invalidate(), it occurred in the same situation.
I'm not familiar with Android. Why is it like this?
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: EglSwapBuffers exception on Android

Post by Wolfmanfx »

can you post the modified code (Ogre JNI where open and close a dialog )
CloudJin
Gnoblar
Posts: 13
Joined: Fri Jun 28, 2013 7:09 am

Re: EglSwapBuffers exception on Android

Post by CloudJin »

Heres the showing dialog code.

Code: Select all

protected void dialog() { 
	        AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); 
	        builder.setMessage("确定要退出吗?"); 
	        builder.setTitle("提示");
	        //builder.setView(mView);
	        builder.setPositiveButton("OK", 
	                new android.content.DialogInterface.OnClickListener() { 
	                    @Override 
	                    public void onClick(DialogInterface dialog, int which) { 
	                        dialog.dismiss(); 
	                    } 
	                }); 
	        builder.setNegativeButton("Cancel", 
	                new android.content.DialogInterface.OnClickListener() { 
	                    @Override 
	                    public void onClick(DialogInterface dialog, int which) { 
	                        dialog.dismiss(); 
	                    } 
	                }); 
	        AlertDialog dialog = builder.create();
	        dialog.show();
	    } 
		
		public void OpenShare(final String text)
		{	
			((CloudApplication) mActivity).onOpenDialog();
			dialog();
		}

public void onOpenDialog()
{
	handler.removeCallbacks(renderer);
}
When I push button in my game, I call OpenShare() to show the test dialog. And call handler.removeCallbacks(renderer) in onOpenDialog().
Because I found if I don't call handler.removeCallbacks() the dialog had render issue.
When I push the cancel button to close the dialog, I call handler.post(renderer) to loop.
But the Ogre throw the swap buffer exception.

Are there something wrong?
CloudJin
Gnoblar
Posts: 13
Joined: Fri Jun 28, 2013 7:09 am

Re: EglSwapBuffers exception on Android

Post by CloudJin »

Another question: if the activity lost the focus, Ogre throw the swap buffer exception. How to deal with the losing focus on Android?
Thanks.
CloudJin
Gnoblar
Posts: 13
Joined: Fri Jun 28, 2013 7:09 am

Re: EglSwapBuffers exception on Android

Post by CloudJin »

Well, I solve it.
The EGL error is EGL_BAD_CONTEXT, so I guess there is something wrong with context.
Then I add a method into AndroidEGLWindow:

Code: Select all

void AndroidEGLWindow::_resetContext()
    {
        mContext->endCurrent();
        mContext->setCurrent();
    }
And call the method in onWindowFocusChanged(boolean hasFocus) like this:

Code: Select all

handler.post(new Runnable() {
					public void run() {
						OgreActivityJNI.resetContext();
					}
				});
The issue can be solved.
But I yet don't know why occur the EGL_BAD_CONTEXT error.
Post Reply