Error: EXC_BAD_ACCESS on line 72 ccCArray.cpp

Error: EXC_BAD_ACCESS on line 72 ccCArray.cpp
0.0 0


Hi all,

I encountered a new problem while filling an array with objects.

This is the thread stack when the error occurs:

void AnimatedCreature::setup(const char * textureName, int lifepoints, int range)
    std::stringstream str;
    str << textureName << "t_";
    this->addAnimation(str.str(), 9, 0.1, 999);

 void AnimatedObject::addAnimation(string str, int numFrames, float tPerFrame, int numOfRounds)
    AnimationClass * anim = new AnimationClass();
    anim->numOfFrames = numFrames;
    anim->numOfRounds = numOfRounds;
    anim->tPerFrame = tPerFrame;
    anim->filename = str;


 void CCArray::addObject(CCObject* object)
    ccArrayAppendObjectWithResize(data, object);


 /** Appends an object. Capacity of arr is increased if needed. */
void ccArrayAppendObjectWithResize(ccArray *arr, CCObject* object)
    ccArrayEnsureExtraCapacity(arr, 1);
    ccArrayAppendObject(arr, object);


 void ccArrayEnsureExtraCapacity(ccArray *arr, unsigned int extra)

    while (arr->max < arr->num + extra) // here the app crashes with EXC_BAD_ACCESS

When I print out what arr~~>max and arr~~>num are, the app crashes there, so it might be, that these values are uninitialized.
What am I doing wrong?

Thanks in advance.


Did you create an array you are accessing?

PS Please wrap your code in < pre > tag.


Yea, I think so. I created a CCSprite subclass which initializes a CCArray like so:

this->animations = new CCArray();

Would it be better to use:

this->animations = CCArray::array();

(Thank you, I was sure there must be a better way than these @’s)


I found the solution.

The problem was that I didn’t initialize the parent object the right way.
I used:

AnimatedCreature * enemy;

instead of:

AnimatedCreature * enemy = AnimatedCreature::create("hero.plist");

These things happen when you don’t get any information about what’s wrong…