Chipmunk the emergence and resolution of zombie physical objects (vii)

Source: Internet
Author: User
Tags addchild

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.