First of all, judging the problem appears in the Star's class method Dostickshorterwork, and then gradually participle comment code, and finally left the following code:
+ (void) Dostickshorterwork: (Stick *) stick{gamescene *gamescene = [Gamescene Sharedgamescene];Ccphysicsnode *physicsworld = (ccphysicsnode*) stick. Parent;@synchronized (Gamescene) {if ([stick. Nameisequaltostring:@"Stickshorter"]) {return;} if ([Stick. Nameisequaltostring:@"Sticklonger"]) {Stick *sticknormal = [Stick sticknormal];Sticknormal. Position= Stick. Position;[Physicsworld Removechild:stick Cleanup:yes];[Physicsworld Addchild:sticknormal];Gamescene. Stickingamescene= Sticknormal;Return;}} cgpoint Position = Stick. Position;__block Stick *stickshorter;@synchronized (gamescene) {stickshorter = [Stick Stickshorter];[Physicsworld Removechild:stick Cleanup:yes];Stickshorter. Position= Position;[Physicsworld Addchild:stickshorter];Gamescene. Stickingamescene= Stickshorter;}}
Omit the stick to shorten the animation and restore the size of the code, the problem remains.
After an n-comment, compile, and run loop, the problem is gradually locked out on stick. Thus again, reasoning involves the possibility of deleting code logic that conflicts with references.
Finally infer what happens if the stick is deleted at this time after the pentagram collision stick in the collision callback!? This is certainly not what the physics engine is willing to see: In a collision callback for a physical object, the physical object is deleted! This is obviously counterintuitive, but it can happen in the app.
If the stick delete code call in the Star class method, the collision callback method does not return, and the stick is gone, and the physical engine considers it to exist.
Simply put, if stick is deleted, the collision callback will appear when the zombie object is running, and if stick is deleted, the collision callback method has returned, then everything is OK. This also matches the random appearance of zombie objects.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Chipmunk the emergence and resolution of zombie physical objects (vii)