Black pictures after a playing time

`hongquan ma

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 found problem just like this.

  1. run TestCpp (ver.2.1.2)
  2. select “DrawPrimitiveTest”
  3. execute “Test CCDrawNode”
  4. press home
  5. resume app

then CCDrawNode can’t draw (blackout).

This problem doesn’t happen in ver.2.1.3 later. maybe #1613

I have this problem too, I use a Xperia Mini Pro(sk17)

I receive 2 errors
“OpenGL error 0x0502 - CCSprite.cpp draw 589”
“OpenGL error 0x0502 - CCTextureAtlas.cpp drawNumberOfQuads 681”

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.

Tested in cocos2d-x 2.1.3 and android 4.0.4.

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.

@Minggo Zhang
It happens quite a lot on galaxy s3
do you have any way to get a galaxy s3 device?

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.

Hi @Minggo , could you test my sample project? (it’s necessary to change the ‘Classes’ path directory)
HelloCpp V2.1.3 Project bug test - http://www.fabiosistemas.com.br/files/HelloCppBugTest.zip

I make tests in two devices, one Xperia Mini Pro(sk17) and on a Galaxy Y Pro, in both devices the problem appears.

Sometimes is necessary close and reopen the app more than once

I create the same test in cocos2d-x version 2.0.4, the issue don’t appear in this version.

good news! we solved this problem in our case.

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.

and the problem GONE.

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?

Hi,

Maybe we are talking about more than one bug?

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?

Thanks,
Surith

@Minggo Zhang
Did you have time to check it more thoroughly?
Thanks!

`folec r said

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.

`dongdong li said

I used v2.1.0 and then update to v2.1.3, the problem is still there
#1613 is did in v2.1.3, so it is nothing about #1613.

`dongdong li
Does you application have memory leak, then it run out of memory?
Or could you send me your game code?

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 :

http://developer.android.com/tools/testing/activity_testing.html#WhatToTest
http://developer.android.com/tools/testing/testing_android.html#Instrumentation

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.

I have purchased an S2 and an S3 devices where my clients report it crashes, and will send a video. This should be next Monday.

Thanks.

JB

@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.

folec r wrote:

> @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… :slight_smile:

I’m talking about the background-foreground black screen error.

>

I think we are mixing too many things here, it looks like everyone tells his history…, Minggo and others will get crazy… :)
>
yes. My thoughts exactly :
) http://cocos2d-x.org/boards/6/topics/27903?r=30542#message-30542
Could you upload your sample app? And maybe create an issue at https://github.com/cocos2d/cocos2d-x/issues? We can track it and try it on different devices.

Thanks.

folec r wrote:

>
> I think we are mixing too many things here, it looks like everyone tells his history…, Minggo and others will get crazy… :)
>
>
yes. My thoughts exactly :
) http://cocos2d-x.org/boards/6/topics/27903?r=30542#message-30542
Could you upload your sample app? And maybe create an issue at https://github.com/cocos2d/cocos2d-x/issues? We can track it and try it on different devices.
>
Thanks.

sure, I uploaded the code previously in this thread: https://www.dropbox.com/s/aaq8i5haow45h7r/test.zip

BTW, do you work in the cocos2dx development team? I didn’t know :slight_smile:

I will also create the issue

folec r wrote:

>
> I think we are mixing too many things here, it looks like everyone tells his history…, Minggo and others will get crazy… :)
>
>
yes. My thoughts exactly :
) http://cocos2d-x.org/boards/6/topics/27903?r=30542#message-30542
Could you upload your sample app? And maybe create an issue at https://github.com/cocos2d/cocos2d-x/issues? We can track it and try it on different devices.
>
Thanks.

issue created, I will try to add a video on Monday or Tuesday if I receive the devices as expected

BTW, do you work in the cocos2dx development team? I didn’t know :slight_smile:

Yes, I work at Zynga on the cocos2d-x team. I am currently working on improving the Android port.