Page 1 of 1

Space.Update crashes with ArgumentOutOfRangeException

Posted: Sun Feb 19, 2012 11:43 pm
by DoctorWhy
I really don't know what information will help solve this issue, but I will try to explain everything leading up to the problem. Just let me know what code/other information you will need to help figure out the problem.

Using the SphereCharacterController as a starting point, I modified things a bit to work with my game. All worked out well. Then, I separated the code into Client and Server project. That is when this error appeared. I create a square that is added to the space, along with the SphereCharacterController. When I collide with the box, it works out well. But when I jump while against the box, the Space.Update() throws the ArgumentOutOfRangeException with "Specified argument was out of the range of valid values. Parameter name: index". Both the client and the server will crash (if I turn on the client side prediction) at the exact same time. All the jumping code has not been modified in the SphereCharacterController. What makes this weird is that it works perfectly in the non-networked version, and all the same code is basically used.

Here is the exception details

Code: Select all

System.ArgumentOutOfRangeException was unhandled
  Message=Specified argument was out of the range of valid values.
Parameter name: index
  Source=BEPUphysics
  ParamName=index
  StackTrace:
       at BEPUphysics.DataStructures.RawList`1.RemoveAt(Int32 index)
       at BEPUphysics.CollisionTests.Manifolds.BoxSphereContactManifold.Remove(Int32 index)
       at BEPUphysics.CollisionTests.Manifolds.BoxSphereContactManifold.Update(Single dt)
       at BEPUphysics.NarrowPhaseSystems.Pairs.StandardPairHandler.UpdateCollision(Single dt)
       at BEPUphysics.NarrowPhaseSystems.NarrowPhase.UpdateBroadPhaseOverlap(Int32 i)
       at BEPUphysics.NarrowPhaseSystems.NarrowPhase.UpdateSingleThreaded()
       at BEPUphysics.MultithreadedProcessingStage.Update()
       at BEPUphysics.Space.DoTimeStep()
       at BEPUphysics.Space.Update()
       at GravitonServer.Levels.Level.Update() in C:\Gravity\GravitonServer\GravitonServer\GravitonServer\Levels\Level.cs:line 109
       at GravitonServer.GameServer.Update() in C:\Gravity\GravitonServer\GravitonServer\GravitonServer\GameServer.cs:line 204
       at GravitonServer.Game1.Update(GameTime gameTime) in C:\Gravity\GravitonServer\GravitonServer\GravitonServer\Game1.cs:line 107
       at Microsoft.Xna.Framework.Game.Tick()
       at Microsoft.Xna.Framework.Game.HostIdle(Object sender, EventArgs e)
       at Microsoft.Xna.Framework.GameHost.OnIdle()
       at Microsoft.Xna.Framework.WindowsGameHost.RunOneFrame()
       at Microsoft.Xna.Framework.WindowsGameHost.ApplicationIdle(Object sender, EventArgs e)
       at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Microsoft.Xna.Framework.WindowsGameHost.Run()
       at Microsoft.Xna.Framework.Game.RunGame(Boolean useBlockingRun)
       at Microsoft.Xna.Framework.Game.Run()
       at GravitonServer.Program.Main(String[] args) in C:\Gravity\GravitonServer\GravitonServer\GravitonServer\Program.cs:line 29
  InnerException: 

Re: Space.Update crashes with ArgumentOutOfRangeException

Posted: Sun Feb 19, 2012 11:54 pm
by Norbo
Given that it doesn't happen in the non-networked version, my first guess would be some asynchronous access. For example, if a network update was received and updated some part of the simulation while the simulation was running, a whole lot of things could explode.

If there isn't any asynchronous fiddling going on, then something else associated with the addition of networking seems to be causing or at least revealing the issue. I can't provide much guidance here, unfortunately. Figuring out how to force the same error without networking would be informative- especially if it can be done reliably.

Re: Space.Update crashes with ArgumentOutOfRangeException

Posted: Mon Feb 20, 2012 12:32 am
by DoctorWhy
The only thing that is done asynchronously is sending and receiving the messages, not consuming them. At least, none of the code I wrote uses their own threads... Looking at the differences between the networked and non-networked versions, there doesn't really seem to be any major changes that I could think would crash BEPU... Things might be in a different place, but that is the extent of the change.

EDIT:
Oh, and on the server, the engine isn't update, only what the user inputs (boolean variables). The update is happening when the SphereCharacterController calls the movement update inside of the Update that the BEPU engine calls (one of the changes I made to the original).

Re: Space.Update crashes with ArgumentOutOfRangeException

Posted: Mon Feb 20, 2012 12:49 am
by DoctorWhy
Oh, I just figured it out. The client and server were crashing at the same time throwing the same error for completely different reasons... how interesting.

One of the things I changed from the non-networked one, for the Server, was taking out the SphereCharacterControllerInput and making all the updates happen in the SphereCharacterController Update that the space.Update calls. So, when it was told to jump while colliding against another space object, there were some inconsistencies.