'System.ArithmeticException'

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

'System.ArithmeticException'

Post by imtrobin »

Reporting, I got this error while firing kinematic entities. Not reproducible.

An unhandled exception of type 'System.ArithmeticException' occurred in BEPUphysics.dll

Additional information: Some internal multithreaded arithmetic has encountered an invalid state. Check for invalid entity momentums, velocities, and positions; propagating NaN's will generally trigger this exception in the getExtremePoint function.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: 'System.ArithmeticException'

Post by Norbo »

What were the circumstances of the exception?
  • In what context did the 'firing' occur? An event? If so, what event?
  • Were multiple kinematic bodies being spawned in the same location?
  • How was the location determined, and how did you determine the movement for the objects?
  • Was there any other configuration done to the fired entity other than moving and changing velocity?
  • Did you happen to look at the inner exception to see where it was coming from specifically?
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: 'System.ArithmeticException'

Post by imtrobin »

I couldn't reproduce it today but it happened twice yesterday.

* In what context did the 'firing' occur? An event? If so, what event?

No, I just created kinematic entities as bullets collisions. It's a machine gun

* Were multiple kinematic bodies being spawned in the same location?

Possibly. Or close to each other.

* How was the location determined, and how did you determine the movement for the objects?

Determined by shooter. Movement is set using LinearVelocity directly


* Was there any other configuration done to the fired entity other than moving and changing velocity?

Yes, I added the shooter to the ignore Specific Entities using NoPair.

* Did you happen to look at the inner exception to see where it was coming from specifically?

No, could not see inside.

It may not be the firing, it might because it hit something and turned in from kinematic and dynamic, as I was spraying the machine gun around the scene. I have 4 large boxes in the size of 100000000 I used as walls though.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: 'System.ArithmeticException'

Post by Norbo »

My first guess would be the walls' sizes. Depending on what's hitting them and how, that size could cause some nasty problems. At the very least, there will be accuracy problems for any colliding shape. The issue could grow in severity if some iterative operations took place, perhaps resulting in a singularity and a NaN somewhere.

I'm guessing that if you fired directly at the walls a lot, you'd see the crash more frequently. The intermittent nature of the crash is a byproduct of the floating point operations involved.

As a possible solution, try removing the entity walls or replacing them with an implicit boundary. You could check for any entities outside of the bounding box by performing a series of space.broadPhase.getEntities queries and removing or destroying any objects found.
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: 'System.ArithmeticException'

Post by imtrobin »

I see. Putting it in the implicit means I would be doing the checks myself, there is not really a point of using the physics, and it makes the code a little messier. The point of using the physics was to get an common event where I destroy the bullet.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: 'System.ArithmeticException'

Post by Norbo »

To clarify, this would only apply to the special case of the huge exterior walls. All the other entity events are fine. Single precision floating point values just don't handle many orders of magnitude difference well in fine-tuned scenarios like physics.

Another possibility would be to shrink the walls down to as small as they could be. You'd want to avoid situations where objects could collide and rest against those large walls, but for a one-shot collision and destruction it should be okay. Numbers on the scale of thousands shouldn't cause any NaN's, but 100,000,000 is too high.
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: 'System.ArithmeticException'

Post by imtrobin »

yeah, I will try to change to smaller numbers and see. Thanks.
Post Reply