Merge pull request #10985 from dabingnn/v3_fixRenderTextureCrash

fix crash problem when switch to a new scene after call RenderTexture::s...
This commit is contained in:
minggo 2015-03-19 20:00:31 +08:00
commit f3e518b103
2 changed files with 5 additions and 1 deletions

View File

@ -107,6 +107,9 @@ public:
/** saves the texture into a file. The format could be JPG or PNG. The file will be saved in the Documents folder.
Returns true if the operation is successful.
Notes: since v3.x, saveToFile will generate a custum command, which will be called in the following render->render().
So if this function is called in a event handler, the actual save file will be called in the next frame. If we switch to a different scene, the game will crash.
To solve this, add Director::getInstance()->getRenderer()->render(); after this function.
*/
bool saveToFile(const std::string& filename, Image::Format format, bool isRGBA = true, std::function<void (RenderTexture*, const std::string&)> callback = nullptr);

View File

@ -146,7 +146,8 @@ void RenderTextureSave::saveImage(cocos2d::Ref *sender)
};
_target->saveToFile(png, Image::Format::PNG, true, callback);
//Add this function to avoid crash if we switch to a new scene.
Director::getInstance()->getRenderer()->render();
CCLOG("Image saved %s", png);
counter++;