Search code examples
cocos2d-x

CCArray "Access violation reading location"


I am using cocos2d-2.0-rc2-x-2.0.1 @ Jun 29 2012 and wrote this

.h

...
protected:
CCArray *array;
...

.cpp

...
bool HelloWorld::init()
{
...
array= CCArray::create(2);
array->addObject(obj1);
array->addObject(obj2);
...
}

void HelloWorld::ccTouchesBegan(CCSet* touches, CCEvent* event)
{
    CCLog("%i", array->count());
}
...

and got this: 0xC0000005: Access violation reading location "0xfeeefeee".

in

CCArray.cpp

unsigned int CCArray::count()
{
    return data->num;
}

Please, help.


Solution

  • try to call

        array->retain() 
    

    after the create. maybe the array is autorealeased after you leave the function.

    but don't forget to release it after you finished.