Array(vector) of CCAction* won't work

i’m working with cocos2d and catch this bug

on Initialize function, i plan to create some CCAction* for use later


CCAnimation* animation = CCAnimation::create(); ... CCAction* action = CCRepeatForever::create(CCAnimate::create(animation)); mActions.push_back(action);
——————

and on an other function, i do


CCAction* action = mActions[index]; mSprite->stopAllActions();/// break point here mSprite->runAction(action);
——————

and it throw an error, i try to put break point and see variable ‘action’ is corrupt

can you please tell me what i’m done wrong???

Try doing action->retain();

Not sure if CCArray automatically retains your stuff, but std::vector doesn’t.

Sam Borenstein wrote:

Not sure if CCArray automatically retains your stuff, but std::vector doesn’t.

If he uses create* on his actions, it should be auto-released.
My suggestion is to replace your
std::vector* with CCArray. IMO, everything with CC in it must be placed in a CCArray if a container is needed and is the best way to do it.

yeah, thank you 2 :smiley: retain() works
i prefer not to use CCArray because i want to reference array member by index. like mActions [99].
but CCArray must travel all over the array.

hu hu wrote:

yeah, thank you 2 :smiley: retain() works
i prefer not to use CCArray because i want to reference array member by index. like mActions[99].
but CCArray must travel all over the array.

You can use *CCArray::objectAtIndex(unsigned int)* to reference member by index.

Lance Gray wrote:

hu hu wrote:
> yeah, thank you 2 :smiley: retain() works
> i prefer not to use CCArray because i want to reference array member by index. like mActions[99].
> but CCArray must travel all over the array.
>
You can use *CCArray::objectAtIndex(unsigned int)* to reference member by index.

thank you