Crash when override CCLayer::draw() and draw sprite

Crash when override CCLayer::draw() and draw sprite
0.0 0



I create class IntroScene : public cocos2d::CCLayer and override draw().
In this class I have 3 sprites.
I want draw my sprites in override function draw()

void IntroScene::draw()
when application call this first time everything allright but in second crash on m_sprite1~~>draw();

Anybody know what is wrong?


Were your sprites added to your Layer?


I don’t add sprite like child to Layer.
if I add a sprite, the layer will draw it ,but I want draw it independently.

I port a game and all control on sprites do framework which I porting.

I necessarily must add sprite to Layer?


But how did you create sprite ? ‘CCSprite* sp = CCSprite::create();’ or ‘CCSprite* sp = new CCSprite(); sp->initWithFile(filename);’?
If you use static method to create sprite, the return pointer is an autorelease object, therefore you need to retain it manually and release it in the destroy-method.


I created my sprite with static method

CCSprite m_sprite1;
m_sprite1 = CCSprite::spriteWithFile;
but now I created like in your question
m_sprite1 = new CCSprite();
and all is allright
I will release it in the destroy-method

Thank you very mutch James Chen for your advice
I will be experimented further