A serious problem

Sep 8, 2008 at 6:50 PM
Hello, in my game, I keep getting an ArithmeticException from Body.cs. The exception is caused by an equation that attempts to calculate using floating-point "Not-a-Number" or NaN values, or specifically, ones being stored (or not stored for that matter) in "angularVelocity" I think it was.

This exception breaks my game within a minute every time I run it, and occurs only during some sort of collision, and more often than not, stronger collisions, but ones that are not or should not be that unheard-of.

How can I bypass this error or fix the problem?
Coordinator
Sep 8, 2008 at 8:55 PM
Edited Sep 8, 2008 at 9:06 PM
Could you tell me where in the code this exception occurs?
When you find the right line of code, try putting in a float.IsNaN() to check if the float is NaN before use.
Developer
Sep 8, 2008 at 9:03 PM
Your gonna have to be more specific or post your code or send it to someone. You can send your code to me (I promise not to steal your idea, I participate in these discusions to help Farseer improve and provide new users with help)
Sep 8, 2008 at 10:26 PM
Edited Sep 8, 2008 at 10:31 PM
I apologize for the simple post; I was in a hurry.$0the problem code is:$0$0$0$0$0rotationalDrag = angularVelocity * angularVelocity * Math.Sign(angularVelocity);in Body.cs.$0$0$0$0$0Secondly, genbox (Jeff), I tried creating an if statement to check for float.IsNaN with:$0$0$0$0$0$0$0$0if (!float.IsNaN(angularVelocity))$0$0                    rotationalDrag = angularVelocity * angularVelocity * Math.Sign(angularVelocity);$0$0                else$0$0                {$0$0                    angularVelocity = 1;$0$0                    rotationalDrag = angularVelocity * angularVelocity * Math.Sign(angularVelocity);$0$0                }$0$0$0$0$0$0$0$0, and that prevented the exception from being thrown, but when the problem happens, all the bodies associated with the collision disappear unless they were static, in which case anything$0$0that touches it from then on out disappears as well.$0$0$0$0$0For instance, if an object has this problem occur by hitting the ground, which is a static body, then everything on the ground disappears, and anything that touches the ground in the future,$0$0disappears too.$0$0$0$0$0I'm lost.$0$0Thanks for the help so far though.$0$0$0
Sep 8, 2008 at 10:37 PM
I apologize for the simple post; I was in a hurry.$0the problem code is:$0$0$0$0$0rotationalDrag = angularVelocity * angularVelocity * Math.Sign(angularVelocity);$0$0$0$0$0in Body.cs.$0$0Secondly, genbox (Jeff), I tried creating an if statement to check for float.IsNaN with:$0$0$0$0$0$0if (!float.IsNaN(angularVelocity))$0$0                    rotationalDrag = angularVelocity * angularVelocity * Math.Sign(angularVelocity);$0$0                else$0$0                {$0$0                    angularVelocity = 1;$0$0                    rotationalDrag = angularVelocity * angularVelocity * Math.Sign(angularVelocity);$0$0                }$0$0$0$0$0$0, and that prevented the exception from being thrown, but when the problem happens, all the bodies associated with the collision disappear unless they were static, in which case anything$0$0that touches it from then on out disappears as well.$0$0For instance, if an object has this problem occur by hitting the ground, which is a static body, then everything on the ground disappears, and anything that touches the ground in the future,$0$0disappears too.$0$0I'm lost.$0$0Thanks for the help so far though.$0
Sep 8, 2008 at 10:38 PM
Why the heck is it doing that???
Coordinator
Sep 9, 2008 at 7:38 AM
Edited Sep 9, 2008 at 7:40 AM
@Oranjoose - You might want to paste the code into notepad before posting it here. What kind of editor are you using?

EDIT: Oh, and I'm not Jeff :) Crashlander (the creator of this project) is Jeff. I'm Ian.
Coordinator
Sep 9, 2008 at 11:28 AM
Usually this means you are using un-realistic values for mass or forces. For instance if you have some really massive bodies and some very light bodies in the same scene, the engine can be prone to "blow-up".  When you see these "NaN's it means the engine can't handle what you are trying to make it do.  Try adjusting the masses in your scene.
Sep 9, 2008 at 3:14 PM
Thank you [real Jeff, sorry about that Ian =/], I'll give it a shot.$0For static bodies and therefore geoms, does it matter what mass I give it?$0$0$0$0
Sep 10, 2008 at 10:09 PM
Edited Sep 10, 2008 at 10:11 PM
I've tried different masses and I'm still able to fairly easily throw the exception with NaN's.

I'm, to put this into better perspective, tossing around a ragdoll I created where the head now has
10 mass; torso: 25 mass; arms: 15 mass each; and legs: 20 mass each, and the ragdoll used to have mass down in the fractions before, but the
problem still occurs.

No idea where to go. =(
Developer
Sep 12, 2008 at 9:46 AM
Didn't read all messages here, but try this http://www.codeplex.com/FarseerPhysics/Thread/View.aspx?ThreadId=29090 ?
Sep 13, 2008 at 5:31 PM

Hey sickbattery, nice find!

For some reason I could not find that thread through searching. I added the code that checks for zero values in Grid.cs, Intersect method, and everything works so far (not much testing).

Cool!