copyWithZone issue when passing pointer to method

copyWithZone issue when passing pointer to method
0.0 0


Hi `all,

I have several classes inheriting from CCNode. There instances get passed as pointers to methods very often in my code (naturally). However, this night I was surprised by getting an assertion failure in CCObject.cpp

CCObject\* CCCopying::copyWithZone(CCZone **pZone)@{CC_UNUSED_PARAM(pZone);CCAssert(0, “not implement”); //<-herereturn 0;}`

I’m trying to pass a pointer to my CCNode derived class. The method signature which causes the attempt to copyWithZone is
virtual void collisionStarted (void* contact) = 0;
yep, it is a pure virtual. I implemented the method in a derived class, as I want to call it from my implementation of b2ContactListener . This is also the reason, why I pass a void**, as this “interface” might be used in several other scenarios, so I dont want to specify a concrete type as parameter.

However, I don’t currently see the reason, why it should try to copy instead of passing the reference.

Maybe some1 has a hint 4 me.

Thx in advance and bregards


I’m not quite familiar with box2d though, I think it’s just plain c++ matter,
from the context, I may presume CCObject::copy() is invoked somewhere in b2ContactListener::collisionStarted native implementation,

In my opinion, you may separate your views and models, drawing stuff in CCNode and storing drawing-related stuff (e.g. position) in some other classes derived from CCObject,
also you may need to implement CCObject::copyWithZone in your CCObject-deriving classes,
for implementation, you may refer to cocos2dx/actions/CCActionInterval.cpp, there’re plenty samples for copyWithZone implementation,

I couldn’t find much fo b2ContactListener from my version of cocos2dx library, so I have pretty little information,
so I’d say the solution has 50/50 chance doesn’t work, ^^


might be just c++, but copy is actually not called. the collisionStarted() method is my own pure virtual method, it is not from b2ContactListener. Sry if my post lead to a misunderstanding there. To be more precise

I have a class that derives from b2ContactListener, lets call it Listener. This class gets an object which encapsulates the b2Body with my CCNode derived class in. In that method implementation, I have some checks and finally call collisionStarted() on my implementation of my pure virtual base class. Lets call this class Resolver. So the workflow is as follows:

  1. Collision between two bodies in box2d
  2. box2d send event to the registered b2ContactListener, which is my class Listener
  3. Listener does his job, with finally calling collisionStarted(void*) on Resolver
  4. HERE the assert fails, I’m not calling copy() though
  5. Resolver should do his job

I don’t get, where copy is called and why, thogh I’m only passing pointers