This project has moved and is read-only. For the latest updates, please go here.

Exception: FPE 3.0 with Silverlight 4.0

Topics: Developer Forum, User Forum
Sep 4, 2010 at 6:30 PM

Hi team, thanks for the great work and congratulations on the successful release of FPE 3.0.

This discussion is about an exception that some experienced with FPE 3.0 in Silverlight. The following solution may save few people some time when the following exception is thrown. This happens when FPE 3.0 runtime gets loaded:

Illegal layout for type 'FarseerPhysics.Collision.ContactID' from assembly 'Farseer Physics 3.0 Silverlight, Version=3.0.3900.2038, Culture=neutral, PublicKeyToken=null': valuetypes with non-public fields may not overlap with other fields.

This is caused by "ContactFeature" structure (in file: Farseer Physics Engine 3.0 Silverlight\Collision\Collision.cs) having non-public data members. Changing all four data members of "ContactFeature" to "public" resolves this problem:

    public struct ContactFeature
        /// <summary>
        /// Feature index on ShapeA
        /// </summary>
        public byte IndexA;

        /// <summary>
        /// Feature index on ShapeB
        /// </summary>
        public byte IndexB;

        /// <summary>
        /// The feature type on ShapeA
        /// </summary>
        public byte TypeA;

        /// <summary>
        /// The feature type on ShapeB
        /// </summary>
        public byte TypeB;

That way, we can keep the struct layout of "ContactID" so it continues to be accessible from C++ codes.

Hope that makes sense and help a few people. Again, thanks for offering such a great physics engine for free, if I ever get to make money from this, I'll make sure I donate some cash for the funding.


Sep 7, 2010 at 10:21 PM

Fixed in 76947

Sep 7, 2010 at 10:41 PM

I'm happy to provide a free physics engine to the .NET community. I hope you get to use it and make some money on it :)