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

'Function does not accept floating point Not-a-Number values.'

Apr 25, 2009 at 11:39 PM
When my game character is in the water, I am randomly getting this error:
"Function does not accept floating point Not-a-Number values.",

which highlights:
            _rotationalDrag = AngularVelocity * AngularVelocity * Math.Sign(AngularVelocity);
in body.cs

I have no ideas of the cause, it happens randomly when there is collisions in the water
Apr 25, 2009 at 11:42 PM
Edited Apr 25, 2009 at 11:45 PM
If AngularVelocity is NaN (Not-A-Number), this error appears.

AngularVelocity can happen when too much force is applied to the geometry. I remember that it was quite easy to get NaN errors from the FluidDragController when the wrong settings was applied to it.
If you send me your code, I can take a look at it.
Apr 26, 2009 at 1:29 AM
thanks for the quick reply,
the code base is actually rather large, and there are numerous spots where forces are applied. Can you be more specific about possible wrong  settings applied to it?
All of the collisions deal with bodys with infinite moment of inertia, if that has something to do with it
Apr 27, 2009 at 2:24 AM
still no progress on this, but here is the code   

public class WaterModel
        #region properties

        public WaveController WaveController { get; private set; }
        public FluidDragController FluidDragController { get; private set; }

        public float WaveGeneratorMax { get; set; }
        public float WaveGeneratorMin { get; set; }
        public float WaveGeneratorStep { get; set; }


        #region public methods

        public WaterModel()
            WaveGeneratorMax = 6; //initial value
            WaveGeneratorMin = 1.5f; //initial value
            WaveGeneratorStep = 0f;

        public void Initialize(PhysicsSimulator physicsSimulator, Vector2 Position, float width, float height)
            //The wave controller controls how the waves move.. how big, how fast, etc..
            //The wave controller is represented as set of points equally
            //spaced horizontally along the width of the wave.
            WaveController = new WaveController();
            WaveController.Position = Position;
            WaveController.Width = width;
            WaveController.Height = height;
            WaveController.NodeCount = 20; //how many vertices make up the surface of the wave
            WaveController.DampingCoefficient = .95f; //determines how quickly the wave will disipate
            WaveController.Frequency = .16f; //determines how fast the wave algorithm runs (seconds)

            //The wave generator parameters simply move an end-point of the wave up and down.
            //Think of a string attached to a wall on one end and held by a person on the other.
            //If the person moves the string up and down to make "waves" then the arm is acting
            //similar to the wave generator. The WaveGeneratorStep property controls how fast the "arm"
            WaveController.WaveGeneratorMax = WaveGeneratorMax;
            WaveController.WaveGeneratorMin = WaveGeneratorMin;
            WaveController.WaveGeneratorStep = WaveGeneratorStep;


            //fluid drag controller controls how things move once IN the water.
            FluidDragController = new FluidDragController();
            FluidDragController.Initialize(WaveController, 0.015f, 4f, 2f, physicsSimulator.Gravity);
            //FluidDragController.Entry = new FluidDragController.EntryEventHandler(onEntry);
            //init with default values.

        public void Reset()

        public void Update(TimeSpan elapsedTime)
            WaveController.Update((float) elapsedTime.TotalSeconds);

it is used by,

                if (Bru.water)
                    water = new WaterModel();
                    water.Initialize(Physics, new Vector2(Bru.x, Bru.y), Bru.width, Bru.height);
                    Bru.Geom.OnCollision += new Geom.CollisionEventHandler(onWaterCollide);

OnWaterCollide is just used to set the entities inWater bool to true
Apr 27, 2009 at 7:34 AM
I've uploaded a XNA water demo to the source control. It works, but the wave rendering is not in place yet. You might be able to see what is wrong with your code, by referencing to the demo from the source control.
Oct 17, 2009 at 2:28 PM
Edited Oct 17, 2009 at 2:29 PM
I encountered the exact same error but it was a completely different thing. I am quite ashamed to admit that it flustered me for at least 4 hours.
Basically I have a sidescroller 2d shooter, similar to stick soldiers. The code below is called when the player shoots a projectile and that projectile collides with something.

The function itself is taken from the AdvancedSamples that come with Farseer, Demo #7, from the Grenade.cs class, and just modified to suit my needs.

Basically whenever I shot a bullet and it collided, it would explode, and the source of the explosion would be the Body object of the projectile.
The only problem with this was that *apparently* it was a bad idea to have the projectile's body affected by the projectile as well lol. It caused the above error, every time, without fail.

So as you can see from the code below, I fixed a condition into the foreach loop to check if the object is NOT a projectile and therefore ignore it.

Hope this helps some poor unfortunate soul from wasting 3-4 hours of time like I did >.<

public void Explode(float Force, float Range)
                Vector2 min = Vector2.Subtract(Body.Position, new Vector2(Range, Range));
                Vector2 max = Vector2.Add(Body.Position, new Vector2(Range, Range));

                AABB aabb = new AABB(min, max);

                foreach (Body body in physSim.BodyList)
                    CustomData cd = (CustomData)body.Tag;
                    if (aabb.Contains(body.Position) && cd.Type != ObjectType.Player && cd.Type != ObjectType.Projectile)
                        Vector2 fv = body.Position;
                        fv = Vector2.Subtract(fv, Position);
                        fv = Vector2.Multiply(fv, Force);
            catch (Exception ex)
                throw new Exception(ex.Message);