I think it is result of remove re-loading textures codes.I found it when test my old game,so i am using version 2.1.2.
May be. But i can not confirm it.
`Jesus Bosch
I am not talking about something different.
On iOS, it doesn’t allow running opengl codes in background.
I am just curious if the device you tested on may work as iOS devices.
I open the game, load some resources using cocosbuilder, then I press back button that call and ad through JNI and call an act.finish() method(act is an Activity), when I try to reopen the app, the error appears.
To make the app open correct again, I need to go to android config and force stop the app.
I upgraded a project from v2.1.2 working fine on all platforms, to v2.1.4, and now I get the same problem running on an Android emulator and on Windows build too… Error 0x502, and sprites swon as white blobs. It happends right from the beginning. The display is never correct.
Strange, I don’t get this error for another two projects I’m working on, as they are quite similar.
I create a simple app using the HelloCpp project in android platform to reproduce the issue.
The only change that I made is in the ‘HelloWorld::menuCloseCallback’ method.
I create a JNI method inside the ‘HelloWorld::menuCloseCallback’, the JNI method just call the ‘finish()’ method from an Activity. When I try to reopen the app, the bug appears.
we found that: the key of the problem is thread safe issue. as long as you always using cocos2dx thread to draw, everything will be ok.
In our case, we get DATA from java, and use that DATA directly to create the cocos2dx layout. Which is WRONG. This causes the thread safe issue.
What did we do
We use queue and schedule to sync the thread. Put the DATA in a queue and using the schedule to get the DATA. Make sure you always using the cocos thread to create stuff.
I found a way to reproduce it:
Try my Example here: https://github.com/tiantian20007/cocos2dx-jpush
I just add a jpush service to the HelloCpp example. And the service is used for get remote push notification from my game server .
step by step:
1 Start a service[http://developer.android.com/reference/android/app/Service.html] in cocos2dx project, any service that will continue to run when you close the app in the task administration bar.
2 Start the game on your android device.
3 Press home button and get to desktop.
4 Long press on the home button, and close your game.
Then, on most device, the main activity[http://developer.android.com/reference/android/app/Activity.html] of your game will be invoked by onDestroy, but the process of your game will not be terminated because the service you started.
(On some device, the process and service will be terminated too, and wo can do this by the [Force to quit] or [强制退出], in this case, we can’t reproduce this issue)
5 You tap your game icon on desktop to restart it: the game will show up with a black screen
And flood by “GL_INVALID_VALUE GL_INVALID_OPERATION cocos2d-x debug info(12583): OpenGL error 0x0502 in […]/cocos2dx/sprite_nodes/CCSprite.cpp draw 589” in logs.
case 1 (you guys talk about): Because lack of memory, the OS destroy your game’s activities, but the process of your game is keep alive;
case 2 (in my project): you close your game manually, but the service your game started keep the process alive;
When you tap the game icon and try to restart it, the process is not restarted actually. Some openGL state is not right for we are not recreating it and we did not clean up the state or clean resources when our activity.onDestory is invoked.
So the solution maybe that we should add some openGL clean up stuff in activity.onDestory ? Any ideas?
Bug 1 : Device runs out of texture memory. Code should unload unused textures.
Bug 2 : When the EGL context is lost, textures are unloaded from graphics memory. This is documented Android behaviour. http://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer.html#onSurfaceCreated(javax.microedition.khronos.opengles.GL10, javax.microedition.khronos.egl.EGLConfig)
Code should recreate all textures in this case.
Bug 3 : Rendering from outside the GL thread. This is not supported.
Perhaps we should file separate bugs and fix them independently?
Bug 2 : When the EGL context is lost, textures are unloaded from graphics memory. This is documented Android behaviour. http://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer.html#onSurfaceCreated(javax.microedition.khronos.opengles.GL10, javax.microedition.khronos.egl.EGLConfig)
Code should recreate all textures in this case.
This is what i did to fix this bug in #1613.
I think `folec r is right. We should separate it into more small issues.
@ron m
Yep. I have to check it more thoroughly. You guys, please make sure you don’t render from outside the GL thread and remove unneeded textures because the memory is limited.
We should add tests for cocos2d-x on Android that test the Activity lifecycle. Android provides a recommended way to do this using the Unit Test and Instrumentation frameworks :
This is designed well for Android app testing. However testing for cocos2d-x is slightly more involved. Questions that I don’t have the answers to :
* How can we programmatically check if a texture has been destroyed?
* How can we programmatically check if a texture has been rendered correctly?
Has anyone already done this with cocos2d-x? If not it is a good idea to investigate using this framework with cocos2d-x.
This will make it easier to avoid lifecycle related bugs in future.
> @Minggo it just happens with the hello world example plus 2-3 1024x1024 ccsprites added to the scene, it is not complex to reproduce.
>
>
Is this about reproducing the background/foreground bug? Or is it about reproducing the bug when the game is running for a long time?
Thanks.
I think we are mixing too many things here, it looks like everyone tells his history…, Minggo and others will get crazy…
I’m talking about the background-foreground black screen error.