Occasional Exception

Jul 28, 2011 at 11:30 PM

Getting a couple of exceptions coming through, i haven't been able to repro the one below.  

 

Exception caught. Message: Value was either too large or too small for an Int32. 

Trace:    at System.Convert.ToInt32(Double value)   

at System.Convert.ToInt32(Single value) 

 at Spritehand.FarseerHelper.PhysicsSprite.Update() 

 at Spritehand.FarseerHelper.PhysicsControllerMain.UpdateDraw()   

at Spritehand.FarseerHelper.PhysicsControllerMain.CompositionTarget_Rendering(Object sender, EventArgs e) 

 at System.Windows.Media.CompositionTarget.OnRendering(Object sender, RenderingEventArgs e)   at MS.Internal.JoltHelper.RaiseEvent(IntPtr target, UInt32 eventId, IntPtr coreEventArgs, UInt32 eventArgsTypeIndex)

In the PhysicsSprite Update method might need a couple of checks around the Convert methods.

 

            int newX = Convert.ToInt32(pos.X);
            if (newX != _X)
            {
                _X = newX;
                Canvas.SetLeft(this, Convert.ToDouble(_X));     
            }

            int newY = Convert.ToInt32(pos.Y);
            if (newY != _Y)
            {
                _Y = newY;
                Canvas.SetTop(this, Convert.ToDouble(_Y));
            }

 

 

            

Somethinglike this maybe?

 

if (pos.X < Int32.MinValue || pos.X > Int32.MaxValue)
                return;

Coordinator
Jul 29, 2011 at 2:56 AM

Whenever I've seen errors like this that are overflowing data values (that is a really, really far out location for a visual element!), it is usually because of some unusual setting in the simulation such as restitution, joint settings, or mass. These can be a bit hard to pinpoint but sometimes an odd setting will cause values to quickly spiral out.