Quantcast
Channel: Cocos Forums - Latest topics
Viewing all articles
Browse latest Browse all 17070

canvasToSave->saveToFile problem

$
0
0

@YuriyKan wrote:

Hello. I have to save an Array of Sprites
here is my code:

void DrawingGame::saveToFileCallback(RenderTexture* texture, const std::string& string)

{
CCLOG("--------file saved %s", string.c_str());
saveNextImage();
}

void DrawingGame::saveNextImage() {
CCLOG("-- saveNextImage %i", imageToSaveIndex);
auto imageToSave = spritesToSave[imageToSaveIndex];
auto canvasToSave = RenderTexture::create(imageToSave->getBoundingBox().size.width, imageToSave->getBoundingBox().size.height, Texture2D::PixelFormat::RGBA8888);
this->addChild(canvasToSave);
Point tempPos = imageToSave->getPosition();
imageToSave->setPosition(imageToSave->getBoundingBox().size.width / 2, imageToSave->getBoundingBox().size.height / 2);
canvasToSave->setPosition(imageToSave->getBoundingBox().size.width / 2, imageToSave->getBoundingBox().size.height / 2);
canvasToSave->begin();
imageToSave->visit();
canvasToSave->end();

std::string fileName = StringUtils::format("image-%i-%i-%i.png", LevelManager::getCurrentPack() + 1, LevelManager::getCurrentLevel() + 1, imageToSave->getTag());


canvasToSave->saveToFile(fileName, Image::Format::PNG, true, CC_CALLBACK_2(DrawingGame::saveToFileCallback, this));


canvasToSave->clear(0.0, 0.0, 0.0, 0.0);
canvasToSave->removeFromParentAndCleanup(true);
canvasToSave = nullptr;

imageToSaveIndex += 1;

}

but app crash in second enter in DrawingGame::saveNextImage() method

logs:
-- saveNextImage 0
--------file saved /var/mobile/Containers/Data/Application/7DE4AF2B-9E94-44D3-B151-21DD398D1A5B/Documents/image-1-1-1000.png
-- saveNextImage 1
Assert failed: Cannot add command while rendering
Assertion failed: (!_isRendering), function addCommand, file /Users/yuriy/Projects/Drawing/cocos2d/cocos/renderer/CCRenderer.cpp, line 379.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 17070

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>