Utils::captureScreen hangs on nexus 9

Hi guys,

I switched my screenshot code to using captureScreen and it’s callback.
It’s working fine (and way faster then the old screenshot code), but while testing it on a Nexus 9 last night, it hang my game. I never got a reply, and I think I wasn’t even getting any updates to my game cycle anymore.

I rebooted the device, started my game, same thing happened.

I then booted up my Nexus 7, updated my game to the latest version (with the new screenshot code) and it worked fine. I had already tested it on a Samsung Galaxy Tab 2 which worked fine as well.

So I figured it had to be something nexus 9 specific, but it was late and I went to bed :smile:

This morning, I tried it on the Nexus 9, and it worked fine…

So I’m happy that it’s working, yet it still feels “scary” that it didn’t work the night before.

Has anyone had issues with the captureScreen code? Is there a way the code can fail without ever calling the callback funtion, for example by ending up in an infinite loop (because that is what it looked like).

I looked at onCaptureScreen in ccUtils, but I don’t see anyway that could hang anything…

@MFHSchoonbrood i also have a problem, when i save a render target to the phone library on android , the saved image it’s empty(black) ,but it worked fine in the ios devices, please help me .

@yagoub Are you using the old render texture code:

cocos2d::Size visibleSize = cocos2d::Director::getInstance()->getVisibleSize();
cocos2d::Point origin = cocos2d::Director::getInstance()->getVisibleOrigin();
auto tex = cocos2d::RenderTexture::create( visibleSize.width, visibleSize.height, cocos2d::Texture2D::PixelFormat::RGBA8888 );
tex->setPosition( (origin.x + visibleSize.width) / 2, (origin.y + visibleSize.height) / 2 );
tex->begin();
cocos2d::Director::getInstance()->getRunningScene()->visit();
tex->end();

std::string imgPath = cocos2d::FileUtils::getInstance()->getWritablePath();
if (imgPath.length() == 0) { return ""; }

bool ret = tex->saveToFile( filename, cocos2d::Image::Format::JPG );
if (ret)
{
    imgPath += filename;
    CCLOG( "save image to %s", imgPath.c_str() );
    return imgPath;
}

or the new captureScreen code:

void Screenshot::TakeScreenshot()
{
    cocos2d::utils::captureScreen( CC_CALLBACK_2( Screenshot::OnScreenshotSaved, this ), "screenshot.jpg" );
}


void Screenshot::OnScreenshotSaved( bool success, const std::string& screenshotFilename )
{
    // Do stuff
}

Thanks @MFHSchoonbrood, please have a look to this topic where i have posted my question. please help me

@yagoub Judging by the canvas code, I’m assuming you’re using the html5 version of cocos2d-x. Unfortunately I have no experience with that… sorry ;(

No, i’m not using html5 , canvas it’s just a name of class