I’m saving a PNG image from a RenderTexture by calling its saveToFile() method. It uses the FileUtils::getInstance()->getWritablePath() method to construct its path. So, if I use a filename, the path will be:
I then try to read that image as a sprite, like so Sprite::create(path), but this fails. Looking under the hood, the method TextureCache::addImage() is called which uses FileUtils::getInstance()->fullPathForFilename().
Stepping through the code, the fail occurs on fopen in CCFileUtils::getData(), which indicates to me that the file does not exist or is not readable. Not sure why it would not be readable or not exist. Anyone?
I am testing this on my iphone, not in the simulator.
Here’s the answer: saveToFile() doesn’t write out to the file path immediately. Instead a render command is added to the renderer, and the renderer will call that command when it is asked to render. My “mistake” was expecting the file to exist immediately. It won’t, until render() is called on the renderer. After calling render() on the renderer, I was able to retrieve the file with no problem. Hope this answer helps someone who encountered this problem.