Black pictures after a playing time

Jesus Bosch wrote:
>

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

Updated the issue with instructions on how to reproduce the bug on the emulator.

@jesus bosch : I created a repository with the test you wrote. Happy to transfer the ownership of the repository to you if you’d like.
https://github.com/folecr/CocosBGFGTest

Thanks.

folec r wrote:

Jesus Bosch wrote:
>
> issue created, I will try to add a video on Monday or Tuesday if I receive the devices as expected
>
Updated the issue with instructions on how to reproduce the bug on the emulator.
https://github.com/cocos2d/cocos2d-x/issues/3029
>
@jesus bosch : I created a repository with the test you wrote. Happy to transfer the ownership of the repository to you if you’d like.
https://github.com/folecr/CocosBGFGTest
>
Thanks.

no problem with the ownership, I just want the problem to be fixed.

A Zynga worker? sounds great! is cocos2d-iphone team moving to cocos2dx?

Hi all, I was facing same problem,
this step helped me to solve this issue

  1. Go to ‘Settings’
  2. Select ‘Developer Options’
  3. Uncheck ‘Do not keep activities’

Thanks
Shailendra

Shailendra More wrote:

Hi all, I was facing same problem,
this step helped me to solve this issue

  1. Go to ‘Settings’
  2. Select ‘Developer Options’
  3. Uncheck ‘Do not keep activities’
    >
    Thanks
    Shailendra

Do you expect our end user to do it to avoid the black screen problem when playing our game?
Your suggestion it just for development convenient but not actually solved the problem.

dirty polarbear wrote:

Shailendra More wrote:
> Hi all, I was facing same problem,
> this step helped me to solve this issue
> 1. Go to ‘Settings’
> 2. Select ‘Developer Options’
> 3. Uncheck ‘Do not keep activities’
>
> Thanks
> Shailendra
>
Do you expect our end user to do it to avoid the black screen problem when playing our game?
Your suggestion it just for development convenient but not actually solved the problem.

Totally agree…

FYI guys, an issue has been created and the cocos2dx team is studying it.

There is a pull request for this issue https://github.com/cocos2d/cocos2d-x/pull/3117
I am not sure if it is correctly.
Could any body helps to review it or test it?

Thanks.

Minggo Zhang wrote:

There is a pull request for this issue https://github.com/cocos2d/cocos2d-x/pull/3117
I am not sure if it is correctly.
Could any body helps to review it or test it?
>
Thanks.

I will test it and let you know

Thanks @Valenti Casas.
Could you please add comment in that pull request?

Minggo Zhang wrote:

Thanks @Valenti Casas.
Could you please add comment in that pull request?

I have merged from your repository with the pool request. I have created a template with the cocos2dx tools and in Android does not compile. It lacks on every Android.mk the flag of C++11, and still then there are errors of includes and after that link errors and in the end it does not work.

Sorry.

I have a same problem.

Problem

  • cocos2dx ver.2.1.4 ( I checked cocos2dx ver.2.1.3 has the same problem)
  • The app is HelloWorld application
  • The devices are Nexus4 and some other devices
  • Modified android manifest (add targetSdkVersion=17)
  • Launch HelloWorld app on the Nexus4
  • Push power button (not home button)
  • Push the power button and unlock the screen
  • Black screen on Test app

When push power button first time, cocos2dx called these methods

  • AppDelegate::applicationDidEnterBackground
  • AppDelegate::applicationWillEnterForeground
  • AppDelegate::applicationDidEnterBackground

Cocos2dx logged a lot of message.
07-12 09:23:37.445: W/Adreno200-ES20(9995): glUseProgram:1386: GL_INVALID_VALUE
07-12 09:23:37.445: D/cocos2d-x debug info(9995): OpenGL error 0x0501 in /path/to/cocos2d-x-2.1.4/projects/Test/proj.android/…/…/…/cocos2dx/sprite_nodes/CCSprite.cpp draw 591

Before modifying manifest file, cocos2dx called AppDelegate::applicationWillEnterForeground at once.

Thanks,

Hi All,
Below code work, but cocos2d team should work on this error
In function applicationWillEnterForeground() of AppDelegate.cpp,
call SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(1) instead of SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic().
and In applicationDidEnterBackground() function,
call SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0) intead of SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic().
this work fine but in logcat give error ‘SpannableStringBuilder SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length’.
cocosd2d team should look in this.

Shailendra More wrote:

Hi All,
Below code work, but cocos2d team should work on this error
In function applicationWillEnterForeground() of AppDelegate.cpp,
call SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(1) instead of SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic().
and In applicationDidEnterBackground() function,
call SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0) intead of SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic().
this work fine but in logcat give error ‘SpannableStringBuilder SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length’.
cocosd2d team should look in this.

Hi, I thought the issue has to do with the graphics, not with the sound…

Hi! I have good news! I solve the problem! So what need to do with 2.1.3 or 2.1.4 versions
And you can check solution in our game: http://play.google.com/store/apps/details?id=com.alawar.fightme

  1. Enable cache on Android by change:

    #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    #define CC_ENABLE_CACHE_TEXTURE_DATA 1
    #else

  2. in main.cpp uncomment comented block

    ccDrawInit();
    ccGLInvalidateStateCache();
    CCDirector::sharedDirector()->setOpenGLView(CCEGLView::sharedOpenGLView());
    CCShaderCache::sharedShaderCache()->reloadDefaultShaders();
    CCTextureCache::reloadAllTextures();
    CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
    CCDirector::sharedDirector()->setGLDefaultValues();

  3. in CCTextureCache.cpp in VolatileTexture::reloadAllTextures() replace this code block

    CCImage pImage;
    unsigned long nSize = 0;
    unsigned char* pBuffer = CCFileUtils::sharedFileUtils()->getFileData(vt->m_strFileName.c_str(), “rb”, &nSize);
    CCLOG(“Reload texture for path: %s”, vt->m_strFileName.c_str());

    if (pImage.initWithImageData((void*)pBuffer, nSize, vt->m_FmtImage))
    {
    CCTexture2DPixelFormat oldPixelFormat = CCTexture2D::defaultAlphaPixelFormat();
    CCTexture2D::setDefaultAlphaPixelFormat(vt->m_PixelFormat);
    vt->texture->initWithImage(&pImage);
    CCTexture2D::setDefaultAlphaPixelFormat(oldPixelFormat);
    }
    CC_SAFE_DELETE_ARRAY(pBuffer);

Tested in all cases on i9100, i9300 Nexus 7, Galaxy Note II

I try your game, it works perfect.

I try to do the changes that you say.

The change two it easy, just uncomment, it’s done.

Change 1, the CC_ENABLE_CACHE_TEXTURE_DATA is defined in the CCTexture2D.cpp file, I just change the code that I find

#if (CC_TARGET_PLATFORM == CC_PLATFORM_EMSCRIPTEN)
    #define CC_ENABLE_CACHE_TEXTURE_DATA       1
#else
    #define CC_ENABLE_CACHE_TEXTURE_DATA       0
#endif

to

#if (CC_TARGET_PLATFORM == CC_PLATFORM_EMSCRIPTEN || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    #define CC_ENABLE_CACHE_TEXTURE_DATA       1
#else
    #define CC_ENABLE_CACHE_TEXTURE_DATA       0
#endif

I receive an error on the line

VolatileTexture::addStringTexture(this, text, dimensions, hAlignment, vAlignment, fontName, fontSize); 

inside the method “CCTexture2D::initWithString” in the CCTexture2D.cpp file.

To compile the project a comment the addStringTexture method.

The change 3 I don’t understand, I need to replace the following code that you describe for what code?

I try to run my game and now it works, I lock and unlock the scrren and the game don’t crash, but I found one small problem, I use the ‘draw’ method to draw some lines in my game, when I lock and unlock the phone, the lines are gone.

But this is not a problem for me, because I can easily replace these lines using a CCSprite.

Thanks “Kirill Bark”, you help me a lot.

It is fixed in this pull request.

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:

Has somebody made this work on cocos2dx 2.1.x releases ?

Thank you.

Hello, everybody.

I’m experiencing the same “black screen when returning to game” issue.
I have a simple runner game that I was working on in cocos2d-2.0-x-2.0.4 and played perfectly: no black screen when returning to the game nor in any other instance.
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:

BTW: Was something changed to CCLabelBMFont? I ask because it’s behaviour changed from 2.0.4 to 2.1.4: I have a CCLabelBMFont that in 2.0.4 when I touch it, the game starts. In 2.1.4, with the same code and assets, the area of the label seems to be SMALLER (like a 10%) of what it used to be. Has anyone seen something like this? Thanks!

Cheers!

Just note that comes from our experience: at first remove all memory leaks and circular referencies (if you’re using smart pointers), at second it’s better to manually recreate objects rendered by CCRenderTexture on resuming (don’t forget that in C++ you have interfaces - I mean pure virtual classes, of course, and can perform some action in base class ctors/dtors).

Sergey Shambir wrote:

Just note that comes from our experience: at first remove all memory leaks and circular referencies (if you’re using smart pointers), at second it’s better to manually recreate objects rendered by CCRenderTexture on resuming (don’t forget that in C++ you have interfaces - I mean pure virtual classes, of course, and can perform some action in base class ctors/dtors).

I have used Visual Leak Detector in Visual Studio and have no leaks, thankfully. What’s weird is that the game running in cocos2d-x 2.0.4 works just fine (turn off screen and when waking up the device the game can still be seen), but with 2.1.4 I encounter the black screen problem after waking up the device. And it’s the exact same code!
I’m using a Galaxy S3, so I don’t know if this happens in other devices.
Also, it happens when I turn off the screen WHILE playing the game. If I first press the Home button to exit the game AND THEN turn off the screen, when I wake the device and go to the game again it works just fine.

How do you manually recreate objects rendered by CCRenderTexture? I mean, do you have some sample code I could take a look at? Thanks! :smiley: