getting thread 1 exc_bad_access (code=1 address in xcode , when trying to loop with CCARRAY_FOREACH

hey i have this code that keep giving me
thread 1 exc_bad_access (code=1 address exception
first i have this
in the class MAPlayfieldLayer : public CCLayer constructer

MAPlayfieldLayer::MAPlayfieldLayer() { gemsInPlay = CCArray::create(); this->scheduleUpdate(); }

and the update method i have :
void MAPlayfieldLayer::update(float dt) { gemsMoving = false; if(gemsInPlay!=NULL) { //See if we have any gems currently moving CCObject *aGemIt; CCARRAY_FOREACH(gemsInPlay,aGemIt) { MAGem *aGem = static_cast<MAGem*>(aGemIt); if (aGem->getGemState() == kGemMoving) { gemsMoving = true; break; } } } }

i allways getting exception on CCARRAY_FOREACH(gemsInPlay,aGemIt)
that say :exc_bad_access (code=1 address in xcode

Did you resolve the problem? I have the same one too.

Seems that the array is autoreleased at the constructor.
Try calling retain() after creating the array.

MAPlayfieldLayer::MAPlayfieldLayer() {
    gemsInPlay = CCArray::create(); 
    gemsInPlay -> retain();
    this -> scheduleUpdate();
}

Don’t forget to release it after you’re done with it.

MAPlayfieldLayer::~MAPlayfieldLayer() {
    gemsInPlay -> release();
}

Thanks Lance it worked