我在2012年6月29日使用了cocos2d-2.0-rc2-x--2.0.1,并编写了这个
.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());
}
...
得到了这个:0xC0000005:读取位置"0xfeeefeee"时发生访问冲突。
在中
CCArray.cpp
unsigned int CCArray::count()
{
return data->num;
}
请帮帮我。
尝试调用
array->retain()
创建之后。离开函数后,数组可能会自动恢复。
但别忘了在完成后发布它。
您也可以这样做:
array = new CCArray();
array->initWithCapacity(3);
create()
返回一个autorelease
CObject。