Segmentation fault when i get texture from a sprite

I got segmentation fault when i execute this code:

void HelloWorld::loadCharacter(cocos2d::Size winS){
_spriteCache = SpriteFrameCache::getInstance();
for (int i = 1; i < 14; i++)
    std::string num = StringUtils::format("%d", i);
    Sprite *sprite = Sprite::create("head"+num+".tiff");
    SpriteFrame *spriteFrame = SpriteFrame::createWithTexture(sprite->getTexture(),sprite->getTextureRect());
_idleAnimation = Animation::createWithSpriteFrames(_idlePlayer, 0.05f);
auto temp_sprite = Sprite::create();
temp_sprite->setPosition(Vec2(winS.width * 0.2, winS.height * 0.5));
auto walk = Animate::create(_idleAnimation);


What is num?

Is a iterator, but this is not the problem.

Its crashes when i call sprite->getTexture() and sprite->getTextureRect()

Here is one way to do it. A loop works great too

I try create a SpriteFrame with a Sprite, passing the texture and rect.

I dont think .tiff format is supported, you should use png or jpg.
First try with single file first.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.