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

Physics2D crashes if an ENTITY_MESH has >8 vertices #79

Closed
mcclure opened this issue Dec 28, 2011 · 1 comment
Closed

Physics2D crashes if an ENTITY_MESH has >8 vertices #79

mcclure opened this issue Dec 28, 2011 · 1 comment

Comments

@mcclure
Copy link
Contributor

mcclure commented Dec 28, 2011

Using Polycode c3c534c with minor patches. I've got some code that looks like:

ScreenMesh *s = new ScreenMesh(Mesh::TRIFAN_MESH);
Mesh *m = s->getMesh();
Polygon *p = new Polygon();
for(vcvi b = points.begin(); b != points.end(); b++) {
    p->addVertex(b->x,b->y,0);
}
m->addPolygon(p);
physics()->addPhysicsChild(s, physicsType, isStatic, friction, density, restitution, isSensor, fixedRotation);

If "points" contains 8 points, this code works fine.

If "points" contains 9 points, this code crashes inside Box2D.

I've seen the crash happen in different places, I've seen it in
#0 0x100161c73 in b2PolygonShape::Set at basic_string.tcc:685
#1 0x1001422e1 in Polycode::PhysicsScreenEntity::PhysicsScreenEntity at basic_string.tcc:685
#2 0x10013f848 in Polycode::PhysicsScreen::addPhysicsChild at basic_string.tcc:685

And also deep inside the render() call, inside something like calculatepolygoncollision(). The top of the stack where the crash occurs always seems to be inside Box2D code.

If there is an unavoidable limitation that Box2D can only go up to 8 vertices, it might be helpful for either the addPhysicsChild to detect we are about to add a too-many-vertices object and fail; or, at least, for this limitation to be documented in the PhysicsScreen documentation.

@Fidelity3
Copy link
Contributor

This issue can be resolved by having multiple fixtures per body that stick to a Max of 8 per polygon. This iss an important issue for people using physics as at the moment you are limited to 8 vertices per object full stop. I have emailed Ivan my fix as if I submit it here (cut and paste) there is some strange tabbing problem and the code looks bad

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

No branches or pull requests

3 participants