utils::captureScreen failed assertion on iOS 13.1.3

Hi, I’m using cocos2d-x 3.17.2 and running my App on iPad mini 5th iOS 13.1.3.

When I call utils::captureScreen, it causes assertion failure.

_validateGetBytes:29: failed assertion `CPU access for textures with MTLResourceStorageModePrivate storage mode is disallowed.’

Here is my code.

string path = FileUtils::getInstance()->getWritablePath().append("screenshot.jpg");
Label *path_lbl = Label::createWithSystemFont(path, "", 20.0);
const char* filename = path_lbl->getString().c_str();
utils::captureScreen([&](bool succeed,const std::string &fileName){}, filename);

and assertion failed on the line: ccUtils.cpp: Line 105

glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.get());

It seems like a MTLResourceStorageMode related problem.

Does anyone know how to fix this?

I run the same code on iOS 11.4.1 iPod touch 6th, and on iOS 12.4.3 iPad mini 2nd, but these 2 devices don’t cause this problem, they run perfect.

Thank you.

1 Like

There is an issue about it: https://github.com/cocos2d/cocos2d-x/issues/20270.

Thank you for sharing related issue.

For my situation, I have a ViewController for showing ads.

If I add the view on to the RootViewController like the code below, and call captureScreen, then assertion failed.

[[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:sharedViewController.view];

Even if I remove the view from RootViewController, and call captureScreen, assertion failed.

Somehow, once I add view on to the RootViewController, assertion failed.
If I never add view, and call captureScreen, then run without assertion failure.

I try to reproduce this situation beginning with default cocos2d-x project, but for the time being , I can’t.

As you mentioned on the github, when I run app via Xcode, assertion failed, but when I run app from device, it doesn’t crash.

Yep, so i think disable metal validation as developers said my be a solution for it.