crash when using CCAnimation::addFrameWithFileName in thread?

crash when using CCAnimation::addFrameWithFileName in thread?
0.0 0


environment: cocos2d-x 0.8.1 / ios4.2 / xcode 3.2.5 / mac 10.6.6

It happens in device and never on simulator。
crash here—> m_pobFrames->addObject(pFrame)
looks like m_popFrames not initialize,it’s null

the sample code is attached. click left close button is ok, click right close button … crash

ps:i’ve removed libs/cocos2dx & libs/cocosdension & build … (195.8 KB)


Hi, Lee. I tested your code, it’s very, very odd.
If you call step3 from a new NSThread

    HelloWorld *pLayer = (HelloWorld *)CCDirector::sharedDirector()->getRunningScene()->getChildByTag(101930);
    if (pLayer) 
        CCSprite *grossini = CCSprite::spriteWithFile("grossini.png");

        CCAnimation* animation = CCAnimation::animationWithName("dance", 0.2f);

        char frameName[100] = {0};
        for( int i=1;i<15;i++)
            sprintf(frameName, "grossini_dance_%02d.png", i);

                // ...

The member variable animation~~>m_nameStr & animation~~>pobFrames are valid after invoking CCAnimation::animationWithName. But after the declaration of char frameName[100], animation~~>m_nameStr is overwritten; and then, after sprintf, animation~~>m_pobFrames is written to a wild pointer, too. That’s why program crashes here.

I tried 2 methods
# use char* pszFrameName = new char[ 100 ], to avoid stack overflow
# invoke animation~~>addFrameWithFileName directly
But it didn’t save the program, animation~~>m_pobFrames is overwritten all the same.

Then I watch the variable via gdb, try to catch who changes this address, but the programe hangs

As I said, it is very very odd.

So my suggestion is: don’t invoke this interface in other thread, just do it in the UI mainloop.