Bug in Breakable Body (FPE3)

Oct 12, 2010 at 7:23 PM
Edited Oct 12, 2010 at 7:24 PM

I try to use a breakable body in my game but I allways get a NullReference Exception.

I found the cause :

        private void Decompose()
            for (int i = 0; i < Parts.Count; i++)
                Fixture fixture = Parts[i];

                //Unsubsribe from the PostSolve delegate
                fixture.PostSolve -= PostSolve;

                Shape shape = fixture.Shape.Clone();


                Body body = BodyFactory.CreateBody(_world);
                body.BodyType = BodyType.Dynamic;
                body.Position = MainBody.Position;
                body.Rotation = MainBody.Rotation;

                body.CreateFixture(shape, fixture.shape.Density);

                body.AngularVelocity = _angularVelocitiesCache[i];
                body.LinearVelocity = _velocitiesCache[i];
body.CreateFixture(shape, fixture.shape.Density);
The method tries to access fixture.Shape after fixture as been destroyed.
I think it's a simple mistake, because the workaround is already present : Shape shape = fixture.Shape.Clone();
You only have to replace body.CreateFixture(shape, fixture.shape.Density); by body.CreateFixture(shape, shape.Density);

Oct 12, 2010 at 7:42 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.