Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solving 'black screen' on android #3117

Merged
merged 2 commits into from Jul 17, 2013

Conversation

jotel
Copy link
Contributor

@jotel jotel commented Jul 9, 2013

Hi,

On Andorid there could be a case that an Activity is Destroyed but the JNI code still stays in memory. In such case OpenGL context is recreated and all currently active CCTexture2D objects (in running scene) which have texture names from the not anymore existing OpenGL context are rendered in black or could render some other textures if the later were created in the mean time.
The typical scenario is when user changes language configuration in his/her device.
To solve that problem the textures' names need to be rebind(reloaded) based on the initial input parameters and as far as I'm aware the only way is to set CC_ENABLE_CACHE_TEXTURE_DATA to 1 and when OpenGL context is reinitiaded then call CCTextureCache::reloadAllTextures(); That way all you textures are valid again. When you have i18n application it could be a good moment to re-init the FileUtils searchPaths and searchResolutionsOrder to enable load localized resources from new locations (based in current language).

Regards
Jaro

p.s. originally i created that patch for 2.1.4 version... but then realised that some work has been done... unfortunately it didn't solve all the cases (and the one most important for me i.e. changing the device locale).. so I hope that would be useful for you.

@minggo
Copy link
Contributor

minggo commented Jul 10, 2013

On Andorid there could be a case that an Activity is Destroyed but the JNI code still stays in memory. In such case OpenGL context is recreated and all currently active CCTexture2D objects (in running scene) which have texture names from the not anymore existing OpenGL context are rendered in black or could render some other textures if the later were created in the mean time.

Good to know, thanks.
Any link to describe it?

@minggo
Copy link
Contributor

minggo commented Jul 10, 2013

If the activity is destroyed, how about kill this program?
Reloading all textures and set up all environment will make codes more complex.
If the activity is destroyed, i think it makes sense to kill the program.

@tiantian20007
Copy link
Contributor

A game may start a service to get push notification. If you kill the program, the service may be killed too.

@jotel
Copy link
Contributor Author

jotel commented Jul 10, 2013

These are mostly my own findings after some time of debugging and
frustration :)

But here are some links which helps:

Activity lifecycle:
http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle
List of activity changes causing to destroy it:
http://developer.android.com/guide/topics/manifest/activity-element.html#config
http://developer.android.com/training/basics/activity-lifecycle/starting.html#Destroy

Jaroslaw Lewandowski

jotel@jotel.net
http://www.linkedin.com/in/jotel

On 10 July 2013 03:36, minggo notifications@github.com wrote:

On Andorid there could be a case that an Activity is Destroyed but the
JNI code still stays in memory. In such case OpenGL context is recreated
and all currently active CCTexture2D objects (in running scene) which have
texture names from the not anymore existing OpenGL context are rendered in
black or could render some other textures if the later were created in the
mean time.

Good to know, thanks.
Any link to describe it?


Reply to this email directly or view it on GitHubhttps://github.com//pull/3117#issuecomment-20718425
.

@minggo
Copy link
Contributor

minggo commented Jul 10, 2013

A game may start a service to get push notification. If you kill the program, the service may be killed too.

Ok.
How about not doing rendering in this case?

@jotel
Copy link
Contributor Author

jotel commented Jul 10, 2013

Yes, this is another solution... you could destroy CCDirector ... but I'm
not sure if you ever considered recreating director in the same process (I
don't have you have ability to kill JNI bindings :) ... so I decided to
patch it that way (most of the code was already there) as It could be the
case that clean shutdown of CCDirector might be more complex.. but yes it
seems to be a better approach if works :) I'll stick with my own solution
in my fork for now /I need something working now / :)

Jaro

Jaroslaw Lewandowski

jotel@jotel.net
http://www.linkedin.com/in/jotel

On 10 July 2013 03:56, minggo notifications@github.com wrote:

If the activity is destroyed, how about kill this program?
Reloading all textures and set up all environment will make codes more
complex.
If the activity is destroyed, i think it makes sense to kill the program.


Reply to this email directly or view it on GitHubhttps://github.com//pull/3117#issuecomment-20718918
.

@minggo
Copy link
Contributor

minggo commented Jul 10, 2013

Thanks @jotel.
I think we have to use this method before finding better solution.

@dumganhar dumganhar merged commit e43281e into cocos2d:develop Jul 17, 2013
@jotel jotel deleted the android-textures-fix branch July 18, 2013 21:45
trarck pushed a commit to trarck/cocos2d-x that referenced this pull request Nov 1, 2013
ray58750034 pushed a commit to ray58750034/cocos2d-x that referenced this pull request Jan 2, 2014
angeltown pushed a commit to angeltown/cocos2d-x that referenced this pull request Apr 28, 2014
angeltown pushed a commit to angeltown/cocos2d-x that referenced this pull request Apr 29, 2014
angeltown pushed a commit to angeltown/cocos2d-x that referenced this pull request Apr 29, 2014
angeltown pushed a commit to angeltown/cocos2d-x that referenced this pull request Apr 30, 2014
angeltown pushed a commit to angeltown/cocos2d-x that referenced this pull request Apr 30, 2014
angeltown pushed a commit to angeltown/cocos2d-x that referenced this pull request Apr 30, 2014
angeltown pushed a commit to angeltown/cocos2d-x that referenced this pull request Apr 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants