Issue copying an Array

Issue copying an Array
0.0 0


I have a CCArray with gameobjects. I have to destroy some of them. If I use a CCFOREACH or While, and remove some gameobject from the array, It will compile fine, but some objects could not be used. To solve this problem, I want to make a copy, and destroy all pointers after check if I have to destroy or not, to be sure that I check all of them. So my code is:

CCObject object = NULL;
copyOfGameObjects = CCArray::create(listOfGameObjects);

while (copyOfGameObjects~~>count > 0)
object = copyOfGameObjects~~>objectAtIndex(0);
if (CCRect::CCRectIntersectsRect(object~~>adjustedBoundingBox,CCRectMake))
// Destroy

But I’m getting a Fatal Signal 11 in line

CCArray *copyOfGameObjects = CCArray::create(listOfGameObjects);

Why is this happening?
The method is correct or exist another solution better?


Could you provide more infomations? Your cocos2d-x version?
A demo project to reproduce this issue is better.


If you are using CCArray::createWithArray, please notice that the implementation of this method is using deep copy, so the element class of listOfGameObjects should override copyWithZone method.
Or you could use this way:

CCArray *copyOfGameObjects = CCArray::createWithCapacity(listOfGameObjects->count());



// Create a Copy of all objects in game play
CCArray *copyOfGameObjects = CCArray::create(listOfGameObjects~~>count);

Work properly.