Null normals exception

Topics: User Forum
Mar 13, 2011 at 1:15 AM
Edited Mar 13, 2011 at 1:16 AM

I'm trying to create two bodies. One is a static object with two shapes - a rectangle + a poly. The other is dynamic rectangle. When I run the simulation and the two bodies are about to collide, I get a normals are null exception.

The exception occurs in FindMaxSeparation when the dot product is being calculated -

float dot = Vector2.Dot(poly1.Normals[i], dLocal1);

Am I doing something wrong or missing something?

Mar 13, 2011 at 1:52 AM

Ah figured it out. I should have used DestroyFixture to remove a fixture. Earlier I had simply deleted the thing in FixtureList.

Jul 24, 2011 at 6:24 PM
Edited Jul 24, 2011 at 6:40 PM

Hello there,

I have exactly the same problem, though the OP's description doesn't make sense to me at all, so if anyone could explain it or give another solution I would be most grateful. I'm using the latest version of Farseer (3.3.1) along with FlatRedBall and XNA 4. Here is my polygon creation code:

        public static Fixture CreateFarseerEntityFromPoly(Polygon source, BodyType bodytype)
        {
            Body body = BodyFactory.CreateBody(physicsworld);
            body.BodyType = bodytype;
            body.Rotation = source.RotationZ;
            PolygonShape shape = new PolygonShape(1);
            Vertices verts = new Vertices();
            foreach (FlatRedBall.Math.Geometry.Point point in source.Points)
            {
                Vector2 pointvector = new Vector2((float)point.X, (float)point.Y);
                verts.Add(pointvector);
            }
            FarseerPhysics.Common.Decomposition.BayazitDecomposer.ConvexPartition(verts);
            shape.Vertices.AddRange(verts);
            Fixture fixture = body.CreateFixture(shape);
            fixture.Body.Position = new Vector2(source.X, source.Y);
            return fixture;
        }

Thanks,
-egg651 

 

EDIT:
I fixed the problem by making a minor change to my polygon creation code. Changed lines are in bold:

        public static Fixture CreateFarseerEntityFromPoly(Polygon source, BodyType bodytype)
        {
            Body body = BodyFactory.CreateBody(physicsworld);
            body.BodyType = bodytype;
            body.Rotation = source.RotationZ;
            Vertices verts = new Vertices();
            foreach (FlatRedBall.Math.Geometry.Point point in source.Points)
            {
                Vector2 pointvector = new Vector2((float)point.X, (float)point.Y);
                verts.Add(pointvector);
            }
            FarseerPhysics.Common.Decomposition.BayazitDecomposer.ConvexPartition(verts);
            PolygonShape shape = new PolygonShape(verts, 1);
            Fixture fixture = body.CreateFixture(shape);
            fixture.Body.Position = new Vector2(source.X, source.Y);
            return fixture;
        }
However, I now get an Assertion Failed error - Though I will start a new discussion for that.