Float is a NaN Exception

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Zardoz
Posts: 2
Joined: Sat Dec 01, 2012 12:43 am

Float is a NaN Exception

Post by Zardoz »

I'm getting this exceptio using Bepu and VS don't showme were of my code is generating the NaN. I only know that the NaN it's getting to Bepu and generating this error. The most strange thing it's that is a heinser-bug, becasue only sometimes happens. Usually shows when I try to generate more that 100 zombies at random inside a rectangle and I allow the zombies to fall some meters over a staticmesh. (Note: I try to generate it using a loop and modules, so not was random positions with the same error showing)

No se controló System.ArithmeticException
Message=Function does not accept floating point Not-a-Number values.
Source=mscorlib
StackTrace:
at System.Math.Sign(Single value)
at BEPUphysics.CollisionShapes.ConvexShapes.CylinderShape.GetLocalExtremePointWithoutMargin(Vector3& direction, Vector3& extremePoint)
at BEPUphysics.CollisionTests.CollisionAlgorithms.MinkowskiToolbox.GetLocalMinkowskiExtremePoint(ConvexShape shapeA, ConvexShape shapeB, Vector3& direction, RigidTransform& localTransformB, Vector3& extremePoint)
at BEPUphysics.CollisionTests.CollisionAlgorithms.MPRToolbox.LocalSurfaceCast(ConvexShape shapeA, ConvexShape shapeB, RigidTransform& localTransformB, Vector3& direction, Single& t, Vector3& normal)
at BEPUphysics.CollisionTests.CollisionAlgorithms.TriangleConvexPairTester.DoDeepContact(TinyStructList`1& contactList)
at BEPUphysics.CollisionTests.CollisionAlgorithms.TriangleConvexPairTester.DoExternalNear(TinyStructList`1& contactList)
at BEPUphysics.CollisionTests.CollisionAlgorithms.TriangleConvexPairTester.GenerateContactCandidate(TinyStructList`1& contactList)
at BEPUphysics.CollisionTests.Manifolds.TriangleMeshConvexContactManifold.Update(Single dt)
at BEPUphysics.NarrowPhaseSystems.Pairs.StandardPairHandler.UpdateCollision(Single dt)
at BEPUphysics.NarrowPhaseSystems.NarrowPhase.UpdateBroadPhaseOverlap(Int32 i)
at BEPUphysics.Threading.ParallelLoopWorker.Work()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Float is a NaN Exception

Post by Norbo »

Try compiling BEPUphysics with the CHECKMATH compilation symbol. That will insert a whole bunch of validation code in all the common access points; it should catch the invalid values earlier in their propagation. Additional validations may be required to narrow the cause down fully.
tehDrop
Posts: 20
Joined: Sat Dec 03, 2011 3:58 am

Re: Float is a NaN Exception

Post by tehDrop »

Hi, I'm getting the same exact exception and it also happens randomly and occasionally so it's really hard to tell why it's happening.

I'm using the latest development version and it didn't happen in the previous version I was using (1.2.0). I'm also using character controllers and static meshes.

I just compiled with CHECKMATH and will update if it happens again.
tehDrop
Posts: 20
Joined: Sat Dec 03, 2011 3:58 am

Re: Float is a NaN Exception

Post by tehDrop »

Hi, just happened to me again... here's the exception details (compiled with CHECKMATH):

System.NotFiniteNumberException was unhandled
Message=Invalid value.
Source=BEPUutilities
OffendingNumber=0.0
StackTrace:
at BEPUutilities.MathChecker.Validate(Vector3 v)
at BEPUphysics.Entities.Entity.ApplyLinearImpulse(Vector3& impulse)
at BEPUphysics.Constraints.Collision.ContactPenetrationConstraint.ExclusiveUpdate()
at BEPUphysics.Constraints.Collision.NonConvexContactManifoldConstraint.ExclusiveUpdate()
at BEPUphysics.SolverSystems.Solver.MultithreadedPrestep(Int32 i)
at BEPUphysics.Threading.ParallelLoopWorker.Work()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Float is a NaN Exception

Post by Norbo »

Interesting; there's not anything known which should cause that. If I had to guess, an invalid contact was generated. Perhaps it's some degenerate geometry configured in such a way that it can sneak through the existing protections in the contact generator. Another option is that the contact was modified after the fact. Perhaps in an event, or an asynchronous context (leading to corruption of one kind or another).

As for the next step- I can't reproduce it locally, so if you can isolate the issue in a debuggable project that reproduces the issue, that would help. Or, just sprinkle a whole bunch more MathChecker.Validates, particularly over anywhere which could be generating invalid contact data. That is roughly what I would end up doing :)
tehDrop
Posts: 20
Joined: Sat Dec 03, 2011 3:58 am

Re: Float is a NaN Exception

Post by tehDrop »

Finally found the issue... the static mesh had a place with a duplicate quad on the ground and every time character controllers got close to the vertices the exception happened.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Float is a NaN Exception

Post by Norbo »

I can't seem to create a mesh which behaves similarly; could you share the content which triggers the failure? I should be able to protect against it.
tehDrop
Posts: 20
Joined: Sat Dec 03, 2011 3:58 am

Re: Float is a NaN Exception

Post by tehDrop »

Here's the mesh:
mesh.zip
(6.49 KiB) Downloaded 497 times
Put it in the BEPUphysicsDemosContent folder and change this line in the CharacterPlaygroundDemo:
var staticMesh = new StaticMesh(staticTriangleVertices, staticTriangleIndices, new AffineTransform(new Vector3(1f, 1f, 1f), Quaternion.Identity, new Vector3(0, 0, 0)));

Then walk back and forth with the character in this spot:
mesh.png
mesh.png (18.6 KiB) Viewed 8301 times
Also, I was wrong, it's not a duplicated quad, it's an extrude of the selected quad in the picture with no translation (so 4 new quads in total as "edges")
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Float is a NaN Exception

Post by Norbo »

Alright, it should now be fixed in the development version.

Thanks for the report and reproduction content!
tehDrop
Posts: 20
Joined: Sat Dec 03, 2011 3:58 am

Re: Float is a NaN Exception

Post by tehDrop »

Thanks for fixing it!
Post Reply