Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

b2ChainShape::CreateLoop causes odd behavior when first and last vertice are the same #340

Open
GoogleCodeExporter opened this issue Apr 16, 2016 · 1 comment

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Make a static body with chain fixture box built with CreateChain starting at 
top left and going clockwise (should require 5 verts)
2. Try changing the fixture to use CreateLoop with the same verts
3. Put a dynamic body on top of the body

What is the expected output? What do you see instead?

Objects fall into the inside of the chain shape / have unpredictable collision 
with the object.


Please provide any additional information below.

This is happening because b2ChainShape::CreateLoop is trying to add the last 
vertex itself, and in doing so is actually causing the same vertex to be 
repeated twice which invalidates the b2_linearSlop assert which I am sure is 
there for good reason.

My suggested fix would be to only add the new vertex if...

b2DistanceSquared(vertices[0], vertices[count-1]) > b2_linearSlop * 
b2_linearSlop

...so that the same vert list would be compatible with both CreateLoop and 
CreateChain without change. In the case where the first and last vertex are the 
same, or very close, the function should operate the same as CreateChain while 
also setting up prevVertex/nextVertex appropriately.

Original issue reported on code.google.com by [email protected] on 29 Oct 2014 at 6:50

@GoogleCodeExporter
Copy link
Author

Adding patch file which probably better demonstrates what I mean.

This is based off box2d-2.3.0

Original comment by [email protected] on 29 Oct 2014 at 7:00

Attachments:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant