hushaojie04 / libgdx

Automatically exported from code.google.com/p/libgdx
0 stars 0 forks source link

ChainShape in Body.createFixture throws c++ runtime #450

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
ChainShape chainShape = new ChainShape();
BodyDef railBodyDef = new BodyDef();
railBodyDef.type = BodyType.StaticBody;
railBodyDef.position.set(new Vector2(3,3));

Body railBody = CURRENT_WORLD.createBody(railBodyDef);
chainShape.setNextVertex(new Vertex2(1,1));
chainShape.setNextVertex(new Vertex2(2,2));

FixtureDef fixDef = new FixtureDef();
fixDef.shape = chainShape;
fixDef.density = 0f;
fixDef.friction = 1f;
fixDef.restitution = 1;

railBody.createFixture(fixDef); <-- C++ runtime error here

ALSO TRIED:

railBody.createFixture(chainShape, 0.0f); <-- Same error here

Original issue reported on code.google.com by c33jd13...@gmail.com on 9 Sep 2011 at 7:43

GoogleCodeExporter commented 9 years ago
There's a bug with the implementation of Box2D's prismatic joint.  See the 
following threads:

http://box2d.org/forum/viewtopic.php?f=4&t=7544
http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=1879

If you grab the latest Box2D repo, you'll get Erin's latest updates.  
Specifically, the following files need to be modified:

The following files require updates:

b2PrismaticJoint.cpp
b2PrismaticJoint.h
b2Math.h

Note that some of the member names of b2PrismaticJoint have changed, so if you 
limit the fix to those files, they'll need to be updated to their previous 
value (m_refAngle instead of m_referenceAngle).

I'm attaching a patch with the changes I made locally.

Original comment by tescott...@gmail.com on 12 Sep 2011 at 11:16

Attachments:

GoogleCodeExporter commented 9 years ago
ChainShape actually works, i didn't expose two vital methods: createLoop and 
createChain :/ the next/prev vertex methods will only work if you created loops 
and chains first. (See Box2DTest). 

I also merged the latest Box2D SVN head with our version, so all the latest 
fixes are in, including the prismatic joint fixes.

Original comment by badlogicgames on 18 Sep 2011 at 9:10