[SOLVED] 3.0beta2 error on resume

Im using 3.0beta2 and testing my game on android 4.0.
I’m using facebook sdk to share something on facebook, then after the app resumed, I got this error

D/cocos2d-x debug info(15430): OpenGL error 0x0502 in \proj.android…/cocos2d/cocos/2d/CCTextureAtlas.cpp drawNumberOfQuads 701
E/Adreno200-ES20(15430): <qgl2DrvAPI_glDrawElementsInstancedXXX:689>: GL_INVALID_VALUE

Is it a bug?

How did you use facebook?
cocos2d-x is not thread safe.

Tried the newest source code from github, without success.

I called facebook sdk using jni

void FacebookInterface::login(int cbIndex,const char* scope){
	
	cocos2d::JniMethodInfo t;
	if (cocos2d::JniHelper::getStaticMethodInfo(t
		, FBJavaClassName
		, "login"
		, "(ILjava/lang/String;)V"))
	{
		if (scope)
		{
			jstring jeventId = t.env->NewStringUTF(scope);
			t.env->CallStaticVoidMethod(t.classID, t.methodID, cbIndex,jeventId);
			t.env->DeleteLocalRef(jeventId);
		} 
		else
		{
			t.env->CallStaticVoidMethod(t.classID, t.methodID, cbIndex,NULL);
		}
		t.env->DeleteLocalRef(t.classID);
	}  
}

which calls code from facebook java sdk

public static void login(final int cbIndex, final String scope) {
		mActivity.runOnUiThread(new Runnable() {

			@Override
			public void run() {
				
				Session session = Session.getActiveSession();
				if (session == null) {
					session = new Session(mContext);
					Session.setActiveSession(session);
				}
		
				String[] permissions = null;
				mNeedPublishPermissions = false;
				if (scope != null) {
					permissions = scope.split(",");
					for (int i = 0; i < permissions.length; i++) {
						if (allPublishPermissions.contains(permissions[i])) {
							mNeedPublishPermissions = true;
							break;
						}
					}
				}
		
				if (session.isOpened()) {
					if (scope == null
							|| session.getPermissions().containsAll(
									Arrays.asList(permissions))) {
						Log.e(Tag, "FB.login() called when user is already connected.");
					} else {
						mStatusCallback.mCallByMode = SessionStatusCallback.CallByLogin;
						mStatusCallback.mCallbackIndex = cbIndex;
						if (mNeedPublishPermissions) {
							session.requestNewPublishPermissions(new Session.NewPermissionsRequest(
									mActivity, Arrays.asList(permissions)));
						} else {
							session.requestNewReadPermissions(new Session.NewPermissionsRequest(
									mActivity, Arrays.asList(permissions)));
						}
					}
				} else {
					mStatusCallback.mCallByMode = SessionStatusCallback.CallByLogin;
					mStatusCallback.mCallbackIndex = cbIndex;
		
					if (!session.isClosed()) {
						mOpenRequest = new Session.OpenRequest(mActivity);
						if (permissions != null)
							mOpenRequest.setPermissions(Arrays.asList(permissions));
						mOpenRequest.setCallback(mStatusCallback);
		
						if (mNeedPublishPermissions)
							session.openForPublish(mOpenRequest);
						else
							session.openForRead(mOpenRequest);
		
					} else
						Session.openActiveSession(mActivity, true, mStatusCallback);
				}
			}
		});
	}

So it’s not a bug from the new renderer? What should I do to make it thread safe?

I tried calling admob from plugin-x, but it’s error also, I opened a thread here

I think you should invoke login through Activity.runOnUiThread().

I’ve done that, you can see my code above.
facebook activity has been called, and brought up to the front, then when it gets back to cocos2dxactivity, it spits error like on post #1

okay, I got admob plugin-x to show some ads, but still there is some error keep logging when it’s still running

OpenGL error 0x0501 in \proj.android…/cocos2d/cocos/2d/CCTextureAtlas.cpp drawNumberOfQuads 701
E/Adreno200-ES20(11079): <qgl2DrvAPI_glDrawElementsInstancedXXX:689>: GL_INVALID_VALUE
E/dalvikvm(11079): JNI ERROR: env->self != thread-self (0x12f0f60 vs. 0x1342050); auto-correcting

Yep. You use Activity.runOnUiThread() to invoke login.
Sorry for my careless.

I have not idea now.
From the error message, it seems that invoking JNI from different thread.
So after plugin activity back to cocos2d-x activity, did you invoke engine code directly in UI thread?

@siauw, Thanks for your feedback!
What’s your app performance when the error is logged?
Is it crashed? Black screen? No response? Or only have this error log with everything else is well?

Could you upload a demo project to reproduce this problem? Then I can debug & find the reason much quicker.
Thank you once more.

the game goes to black screen when I got that error log, then after a while it’s crashed and back to os menu :frowning: I just use the code from HelloPlugins. I will sort my code, then I will attach my project here.

D/cocos2d-x debug info(28683): OpenGL error 0x0501 in \proj.android…/cocos2d/cocos/2d/CCTextureAtlas.cpp drawNumberOfQuads 701
E/Adreno200-ES20(28683): <qgl2DrvAPI_glDrawElementsInstancedXXX:689>: GLINVALIDVALUE

It seems that OpenGL context lost.

any update on this?
it seems like a bug on the renderer. I tested without any plugin-x running. I still got black screen on application resume from os main menu, with this error

D/cocos2d-x debug info(13293): OpenGL error 0x0502 in \proj.android…/cocos2d/cocos/2d/CCTextureAtlas.cpp drawNumberOfQuads 701
E/Adreno200-ES20(13293): <qgl2DrvAPI_glDrawElementsInstancedXXX:689>: GL_INVALID_VALUE

maybe there is connection to this old thread

I opened CCRenderTexture and there is still this comment
//TODO move this to configration, so we don’t check it every time
/* Certain Qualcomm Andreno gpu’s will retain data in memory after a frame buffer switch which corrupts the render to the texture. The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture. Create a temporary texture to overcome this. At the end of RenderTexture::begin(), switch the attached texture to the second one, call glClear, and then switch back to the original texture. This solution is unnecessary for other devices as they don’t have the same issue with switching frame buffers.
*/

so is it not fixed yet?

What’s the engine version you used?
How to reproduce it step by step?
Thanks.

zhangxm might be right, you probably lost your gl context.
try to save it.

@zhangxm
i’m using cocos2d-x 3.0beta2.
I’ll send you my project, may I know your email address?

@newstar55a
I’ll google how to save gl context… thanks for your info :slight_smile:

Thanks. Please give me a simple demo to reproduce this issue.
My email is xiaoming.zhang@cocos2d-x.org

you can use this on the part where EGL is initialize
GLSurfaceView.setPreserveEGLContextOnPause(true)

although i was thinking that the context should be reinitialize when the execution returns to your GL codes.I had this live wallpaper app before where it restarts everything when i go to app drawer then return to home.but there where no errors it just get restarted. it depends on how you initialize your context though, so when i save the context and the focus returns to my codes it just resume from where it was rendering, smooth.
My solution may not apply to your issue but you can at least try. :wink: cheers.

@zhangxm
I’ve sent an email to you

I attached the project in here also, so other people can try :slight_smile:

I can reproduce the bug only using the hellocpp demo with 2 scenes.

  1. run the game
  2. push the button in the middle to go to next scene
  3. entered next scene, which I render SpriteBatchNode background, and 3 sprites.
  4. push home button on your phone
  5. get back to the game

If it’s still okay then continue with
7. press button on the corner to go back to previous scene
8. press the button in the middle again to go to next scene
9. entered next scene where I render background and 3 sprites , press button on the corner to go back to previous scene again
10. press home button on phone
11. get back to the game again

On my phone that will generate error losing GL context like I describe on my previous post. If it’s not error, try repeat step 8-11 again, maybe 2 more times.

From what I see in the log, the SpriteBatchNode children keep raising every time the game resume from background.

Hope it can be resolved.

Thanks.
I have received it.

@newstar55a
I can’t find GLSurfaceView class on version 3.0beta2… It must have been removed…

sorry siauw that’s not part of cocos2dx, that’s part of the android sdk and openGL.
I actually haven’t played with cocos2dx-3.0 so i don’t know how the context was initialize but you can look at your project’s activity class (maybe onCreate method) where the EGL was initialize, this is the one you use to configure the GL context to glue or create a bridge between openGL and the native platform display and all the surface, buffers, window size, etc…