.NET Native bug and solution
Posted: Sun Dec 13, 2015 11:09 am
I am using BEPU Physics to make a Windows UWP app. I have made the necessary source code changes most of which are described here viewtopic.php?f=4&t=1926&p=11288.
Everything seemed to work perfectly until I did a .NET Native build. That's when I started getting a System.IndexOutOfRangeException in IntertiaHelper.GenerateSphere(). After spending hours investigating this, it turns out that the calls to edges.TryGetValue() are not working as expected i.e. it is returning false for edges that have already been added to the edges Dictionary (but only in a .NET Native build).
Finally I came across this piece of documentation that helped me find a solution. https://msdn.microsoft.com/en-us/librar ... .110).aspx. The relevant bit being...
Hey presto, it stopped the exception but I was still getting strange behaviour when running the physics engine in .NET Native. I went back and searched the entire code base for classes that implement IEquatable and added the Equals override where it was missing. And now it alls seems to work perfectly.
I'm not sure if this is a .NET Native bug or BEPU Physics bug but I hope this is helpful.
Everything seemed to work perfectly until I did a .NET Native build. That's when I started getting a System.IndexOutOfRangeException in IntertiaHelper.GenerateSphere(). After spending hours investigating this, it turns out that the calls to edges.TryGetValue() are not working as expected i.e. it is returning false for edges that have already been added to the edges Dictionary (but only in a .NET Native build).
Finally I came across this piece of documentation that helped me find a solution. https://msdn.microsoft.com/en-us/librar ... .110).aspx. The relevant bit being...
I saw that TriangleMeshConvexContactManifold.Edge implements IEquatable but does not override the base class Object.Equals() so I provided an implementation as follows:If you implement IEquatable<T>, you should also override the base class implementations of Object.Equals(Object) and GetHashCode so that their behavior is consistent with that of the IEquatable<T>.Equals method.
Code: Select all
public override bool Equals(object obj)
{
return this.Equals((Edge)obj);
}
I'm not sure if this is a .NET Native bug or BEPU Physics bug but I hope this is helpful.