Black pictures after a playing time

@Jesus said
>> yes, but that works only with the new(under development) version of cocos2dx, that changes a lot of namespaces, so it will be really hard to apply to current or previous versions of cocos2dx…

No, it is almost 100% compatible with v2.1.4.

Pablo Mera wrote:

I downloaded cocos2d-x-2.1.4 and ported the same code, with the result of now having the black screen (though the game keeps working: I know because sound is still active). I’ve tried many of the proposed solutions in this thread, but still nothing. If anyone has any other suggestion, please let me know. :slight_smile:

I’m experiencing the same issue.
When events occur in Cocos2dxActivity:

  1. onPause ~~> onResume: it works great.
  2. onPause~~> onCreate: black screen when returning to game. (eg change the system language)

P.S.
I used the bad code, but it helps me:
(./cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java)

@Override
protected void onCreate(final Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    if (sContext != null)
    {
        // restart the application when it is re-created Activiti
        Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage( getBaseContext().getPackageName() );
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(i);
        Cocos2dxHelper.terminateProcess();
    }

    sContext = this;
    this.mHandler = new Cocos2dxHandler(this);
    this.init();
    Cocos2dxHelper.init(this, this);
}

I found out how to reproduce the black screen issue after sleep in my case:

when I start the app with the command “adb shell am start n" it goes black after waking from sleep
when I start the app with the command "adb shell am start
S” or directly from the app browser everything is fine

in both cases I forced the app to stop before executing the command

I’m using cocos2d-x-2.1.4 btw without any of the fixes from this thread

Denis Dolgikh wrote:

[…]
>
P.S.
I used the bad code, but it helps me:
(./cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java)
[…]

Hi, Denis. I tried your code, and the result is that the phone doesn’t go back to the game after waking up, and when getting manually back to the game, it restarts. Even though this is some kind of solution, it’s not what I’m looking for. :frowning:

But thank you very much, anyways. :slight_smile:

Victor . wrote:

I found out how to reproduce the black screen issue after sleep in my case:
>
when I start the app with the command “adb shell am start n" it goes black after waking from sleep
>
when I start the app with the command "adb shell am start
S” or directly from the app browser everything is fine
>
in both cases I forced the app to stop before executing the command
>
I’m using cocos2d-x-2.1.4 btw without any of the fixes from this thread

Hi, Victor.

Thank you for the information. I’m not really sure what those commands do, but searching in Android Developers it says that:
"S: Force stop the target app before starting the activity."
I couldn’t find the
n option for the start command.

So what you are saying is that the problem may be because of the way the app is created and/or sent to the phone? If so, is there anything I could do from Eclipse to solve it? :confused:

Cheers!

  • Pablo

Hi Pablo,
I’m sorry I can’t answer your questions, but did you try to kill the app in the Android app browser and start it again, without using Eclipse?

Victor . wrote:

Hi Pablo,
I’m sorry I can’t answer your questions, but did you try to kill the app in the Android app browser and start it again, without using Eclipse?

Hi, Victor.

Yes, I’ve tried everything, all possible fixes listed in the forums… EXCEPT this one I just found: https://github.com/cocos2d/cocos2d-x/issues/2592

REMOVE THE ** TARGETSDKVERSION IN THE ANDROID MANIFEST.
That’s it. I had “android:targetSdkVersion=”14" in my manifest. Got rid of it and DONE, the problem is absolutely gone.
So, to anyone still having this problem, try NOT specifying the target SDK in the manifest. I still have minsdk and maxsdk, but targetsdk? Get rid of that shit and you’ll have NO black screen after waking up the device.

Thanks Victor and everyone else for your answers! ^^

PS: It would be nice to know WHY this worked, but I think understanding it by myself is kind of out of my reach. To any person working on the framework, if you can shed some light on this, it would be awesome. Now, back to coding a game for me. :slight_smile:

If choice Android build target >= Android 4.0 (API Level >= 14), the black screen will happen every time on many device (Not all devices).
I change to Android 2.3.3 (API Level 10) then it run will.
I will download all API, and try which version’s API will make the black screen bug happen.
As we need the new functions supported by new version Android API, please you wonderful guys fix this bug

REMOVE THE ** TARGETSDKVERSION IN THE ANDROID MANIFEST.
That’s it. I had “android:targetSdkVersion=”14" in my manifest. Got rid of it and DONE, the problem is absolutely gone.

Yes, I updated to 2.1.4 last week and had the same problem. After removing my “android:targetSdkVersion=”14" line it has gone away most of the time, but not 100%. The last version of Arrow Mania was using Cocos2d-x 2.0.2 and didn’t have this issue at all.

Im using a Samsung Galaxy S3 as my main device.

We’ve added this code in Cocos2dxGLSurfaceView.java

protected void initView()
    {
        this.setEGLContextClientVersion(2);
        this.setFocusableInTouchMode(true);
...
        if (Build.VERSION.SDK_INT > 10)
        {
            this.setPreserveEGLContextOnPause(true);
        }
...

Seems to fix most of the problems related to this issue.

Mircea Rila wrote:

Ok, so in our case, this worked out:
in AndroidManifest.xml, add this:
>
android:configChanges=“orientation|screenSize|smallestScreenSize”
>
to your Cocos2D-X activity.
>
This solved our particular problem on Kindle Fire HD 8.9 and Nexus 7. I hope this helps anyone.

Thanks for this! This fixed the black screen issue coming from lock screen.

Mircea Rila wrote:

We’ve added this code in Cocos2dxGLSurfaceView.java
>
[…]
>
Seems to fix most of the problems related to this issue.

Thank you for your help, Mircea…
I tried, But it’s not work.
I use HTC new one for test, Cocos2d-x-2.1.4, Android API Level 14 (4.0.3)
I think I can only change back to the API Level 8 or 9 right now.

Setting minSdk=12 resolved problem for me (minSdk 13 or higher - issue still exists) on Galaxy S4 Mini.
Thanks for your advices!

Hi all, I fixed this issue based on v2.1.4. The Pull Request is here https://github.com/cocos2d/cocos2d-x/pull/3450 .
Could you test it and give me the feedback?

If there aren’t any problems, we will release v2.1.5 which just resolves critical bugs.
Thanks.

Jesus Bosch wrote:

Minggo Zhang wrote:
> It is fixed in this pull request.
>
yes, but that works only with the new(under development) version of cocos2dx, that changes a lot of namespaces, so it will be really hard to apply to current or previous versions of cocos2dx… :frowning:

James Chen wrote:

Hi all, I fixed this issue based on v2.1.4. The Pull Request is here https://github.com/cocos2d/cocos2d-x/pull/3450 .
Could you test it and give me the feedback?
>
If there aren’t any problems, we will release v2.1.5 which just resolves critical bugs.
Thanks.
>
Jesus Bosch wrote:
> Minggo Zhang wrote:
> > It is fixed in this pull request.
>
> yes, but that works only with the new(under development) version of cocos2dx, that changes a lot of namespaces, so it will be really hard to apply to current or previous versions of cocos2dx… :frowning:

Dear James…

Thank you for fix the bug, I try it asap, but some error in Android…
CCTexture2D.cpp:518:55: error: ‘dimensions’ was not declared in this scope
CCTexture2D.cpp:518:67: error: ‘hAlignment’ was not declared in this scope
CCTexture2D.cpp:518:79: error: ‘vAlignment’ was not declared in this scope
CCTexture2D.cpp:518:91: error: ‘fontName’ was not declared in this scope
CCTexture2D.cpp:518:101: error: ‘fontSize’ was not declared in this scope

I think the problem is this function…
bool CCTexture2D::initWithString(const char text, ccFontDefinitiontextDefinition)
{
#if (CC_TARGET_PLATFORM CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM CC_PLATFORM_IOS)

#if CC_ENABLE_CACHE_TEXTURE_DATA
// cache the texture data
VolatileTexture::addStringTexture(this, text, dimensions, hAlignment, vAlignment, fontName, fontSize);
#endif
:
:
}

Best Regard

@Atwood Yen,

Change that line to:

VolatileTexture::addStringTexture(this, text, textDefinition->m_dimensions, textDefinition->m_alignment, textDefinition->m_vertAlignment, textDefinition->m_fontName.c_str(), textDefinition->m_fontSize);

This has already been merged into the dev branch (https://github.com/cocos2d/cocos2d-x/pull/3032) and hopefully will be in the 2.1.5 update.

Justin Hawkwood wrote:

@Atwood Yen,
>
Change that line to:
>
[…]
>
This has already been merged into the dev branch (https://github.com/cocos2d/cocos2d-x/pull/3032) and hopefully will be in the 2.1.5 update.

Dear Justin…

Thank you, I will expecting the Ver 2.1.5.

The Pull Request have not been merged, so you have to pull my branch to test.

Atwood Yen wrote:

James Chen wrote:
> Hi all, I fixed this issue based on v2.1.4. The Pull Request is here https://github.com/cocos2d/cocos2d-x/pull/3450 .
> Could you test it and give me the feedback?
>
> If there aren’t any problems, we will release v2.1.5 which just resolves critical bugs.
> Thanks.
>
> Jesus Bosch wrote:
> > Minggo Zhang wrote:
> > > It is fixed in this pull request.
> >
> > yes, but that works only with the new(under development) version of cocos2dx, that changes a lot of namespaces, so it will be really hard to apply to current or previous versions of cocos2dx… :frowning:
>
Dear James…
>
Thank you for fix the bug, I try it asap, but some error in Android…
CCTexture2D.cpp:518:55: error: ‘dimensions’ was not declared in this scope
CCTexture2D.cpp:518:67: error: ‘hAlignment’ was not declared in this scope
CCTexture2D.cpp:518:79: error: ‘vAlignment’ was not declared in this scope
CCTexture2D.cpp:518:91: error: ‘fontName’ was not declared in this scope
CCTexture2D.cpp:518:101: error: ‘fontSize’ was not declared in this scope
>
I think the problem is this function…
bool CCTexture2D::initWithString(const char text, ccFontDefinitiontextDefinition)
{
#if (CC_TARGET_PLATFORM CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM CC_PLATFORM_IOS)
>
#if CC_ENABLE_CACHE_TEXTURE_DATA
// cache the texture data
VolatileTexture::addStringTexture(this, text, dimensions, hAlignment, vAlignment, fontName, fontSize);
#endif
:
:
}
>
Best Regard

I mean you have to checkout a new branch based on the cocos2d-x/master branch.
Then,

git pull https://github.com/dumganhar/cocos2d-x.git 2.1.5-bug-fixes

James Chen wrote:

I mean you have to checkout a new branch based on the cocos2d-x/master branch.
Then,
[…]

Dear James…

I tried, The bug was gone on my HTC New One, We will try another devices later.
Thanks for you help!

Still expecting new version!

BR.

Atwood