cocos2d iphone - EXC_BAD_ACCESS issue with contact listener -
i getting exc_bad_access error in contact listener code. below code:
main object class (gameobjects) through objects subclassed:
gameobjects.h:
#import "cocos2d.h" #import "ccnode.h" #import "ccphysicssprite.h" #import "box2d.h" #include <math.h> @interface gameobjects : ccnode { //b2body* objectbody_; } -(b2body*)getobjectbody; -(void)objectstouched:(gameobjects*)otherobject; @end
gameobjects.mm (for want cclog tell if it's working):
#import "gameobjects.h" @implementation gameobjects -(b2body*)getobjectbody { } -(void)objectstouched:(gameobjects*)otherobject { cclog(@"it's working"); } @end
contactlistenertest.h:
#import <foundation/foundation.h> #import "cocos2d.h" #import "box2d.h" #import "enemy.h" #import "sprite.h" #import "gameobjects.h" class contactlistenertest : public b2contactlistener { public: b2world* world; void begincontact(b2contact* contact); };
contactlistenertest.mm:
#import "contactlistenertest.h" void contactlistenertest:: begincontact(b2contact *contact) { b2fixture *fixturea = contact->getfixturea(); b2fixture *fixtureb = contact->getfixtureb(); b2body *fixtureabody = fixturea->getbody(); b2body *fixturebbody = fixtureb->getbody(); gameobjects* spriteobject = (gameobjects*)fixtureabody->getuserdata(); gameobjects* spriteobject2 = (gameobjects*)fixturebbody->getuserdata(); [spriteobject objectstouched:spriteobject2]; [spriteobject2 objectstouched:spriteobject]; }
when exc_bad_access error following printed in console:
-[enemy objectstouched:]: unrecognized selector sent instance 0x8558840
enemy 1 of subclasses of gameobjects.
verify userdata object of gameobjects class:
nsassert1([spriteobject iskindofclass:[gameobjects class]], @"userdata %@ not game object", spriteobject); nsassert1([spriteobject2 iskindofclass:[gameobjects class]], @"userdata 2 %@ not game object", spriteobject2);
Comments
Post a Comment