Skip to main content
updated project URL as codeplex is going offline soon, added markdown to code in text
Source Link
Pikalek
  • 13.4k
  • 5
  • 49
  • 54

Does the erroneous line in your World.step()World.step() method have square brackets in it anywhere? Or a get()get() method of some sort with an index in it.

This error suggests that you're asking for an object in an array or list by providing an index outside of the array bounds. Array bounds start at 0, and end at array.Length - 1array.Length - 1.

So a lot of the time this error is caused by looping through objects in an array up to and including array.Lengtharray.Length or list.Countlist.Count

EDIT:

The issue appears to be here (like you suggested):

//Enable the new body nBody.Enabled = true; //Disable the current body mBody.Enabled = false; //Copy the current body's attributes to the new one nBody.SetTransform(mBody.Position, mBody.Rotation); nBody.LinearVelocity = mBody.LinearVelocity; nBody.AngularVelocity = mBody.AngularVelocity; 

I was looking at the code for the .Enabled.Enabled setter in body.csbody.cs in Farseer -- I haven't used Farseer personally so I don't know the exact details of the implementation, but it does a lot of disposing and destroying things when you set enabled to false. I would recommend just rearranging your code like this and giving it a go:

//Enable the new body nBody.Enabled = true; //Copy the current body's attributes to the new one nBody.SetTransform(mBody.Position, mBody.Rotation); nBody.LinearVelocity = mBody.LinearVelocity; nBody.AngularVelocity = mBody.AngularVelocity; //Disable the current body mBody.Enabled = false; mBody = nBody; 

Does the erroneous line in your World.step() method have square brackets in it anywhere? Or a get() method of some sort with an index in it.

This error suggests that you're asking for an object in an array or list by providing an index outside of the array bounds. Array bounds start at 0, and end at array.Length - 1.

So a lot of the time this error is caused by looping through objects in an array up to and including array.Length or list.Count

EDIT:

The issue appears to be here (like you suggested):

//Enable the new body nBody.Enabled = true; //Disable the current body mBody.Enabled = false; //Copy the current body's attributes to the new one nBody.SetTransform(mBody.Position, mBody.Rotation); nBody.LinearVelocity = mBody.LinearVelocity; nBody.AngularVelocity = mBody.AngularVelocity; 

I was looking at the code for the .Enabled setter in body.cs in Farseer -- I haven't used Farseer personally so I don't know the exact details of the implementation, but it does a lot of disposing and destroying things when you set enabled to false. I would recommend just rearranging your code like this and giving it a go:

//Enable the new body nBody.Enabled = true; //Copy the current body's attributes to the new one nBody.SetTransform(mBody.Position, mBody.Rotation); nBody.LinearVelocity = mBody.LinearVelocity; nBody.AngularVelocity = mBody.AngularVelocity; //Disable the current body mBody.Enabled = false; mBody = nBody; 

Does the erroneous line in your World.step() method have square brackets in it anywhere? Or a get() method of some sort with an index in it.

This error suggests that you're asking for an object in an array or list by providing an index outside of the array bounds. Array bounds start at 0, and end at array.Length - 1.

So a lot of the time this error is caused by looping through objects in an array up to and including array.Length or list.Count

EDIT:

The issue appears to be here (like you suggested):

//Enable the new body nBody.Enabled = true; //Disable the current body mBody.Enabled = false; //Copy the current body's attributes to the new one nBody.SetTransform(mBody.Position, mBody.Rotation); nBody.LinearVelocity = mBody.LinearVelocity; nBody.AngularVelocity = mBody.AngularVelocity; 

I was looking at the code for the .Enabled setter in body.cs in Farseer -- I haven't used Farseer personally so I don't know the exact details of the implementation, but it does a lot of disposing and destroying things when you set enabled to false. I would recommend just rearranging your code like this and giving it a go:

//Enable the new body nBody.Enabled = true; //Copy the current body's attributes to the new one nBody.SetTransform(mBody.Position, mBody.Rotation); nBody.LinearVelocity = mBody.LinearVelocity; nBody.AngularVelocity = mBody.AngularVelocity; //Disable the current body mBody.Enabled = false; mBody = nBody; 
Bounty Awarded with 50 reputation awarded by WilHall
Added actual answer below EDIT tag
Source Link
Suds
  • 837
  • 2
  • 8
  • 13

Does the erroneous line in your World.step() method have square brackets in it anywhere? Or a get() method of some sort with an index in it.

This error suggests that you're asking for an object in an array or list by providing an index outside of the array bounds. Array bounds start at 0, and end at array.Length - 1.

So a lot of the time this error is caused by looping through objects in an array up to and including array.Length or list.Count

If you can post your World.stepEDIT:

The issue appears to be here (like you suggested) method,:

//Enable the new body nBody.Enabled = true; //Disable the current body mBody.Enabled = false; //Copy the current body's attributes to the new one nBody.SetTransform(mBody.Position, mBody.Rotation); nBody.LinearVelocity = mBody.LinearVelocity; nBody.AngularVelocity = mBody.AngularVelocity; 

I can probably narrowwas looking at the code for the .Enabled setter in body.cs in Farseer -- I haven't used Farseer personally so I don't know the exact details of the implementation, but it downdoes a bit more forlot of disposing and destroying things when you set enabled to false. I would recommend just rearranging your code like this and giving it a go:

//Enable the new body nBody.Enabled = true; //Copy the current body's attributes to the new one nBody.SetTransform(mBody.Position, mBody.Rotation); nBody.LinearVelocity = mBody.LinearVelocity; nBody.AngularVelocity = mBody.AngularVelocity; //Disable the current body mBody.Enabled = false; mBody = nBody; 

Does the erroneous line in your World.step() method have square brackets in it anywhere? Or a get() method of some sort with an index in it.

This error suggests that you're asking for an object in an array or list by providing an index outside of the array bounds. Array bounds start at 0, and end at array.Length - 1.

So a lot of the time this error is caused by looping through objects in an array up to and including array.Length or list.Count

If you can post your World.step() method, I can probably narrow it down a bit more for you.

Does the erroneous line in your World.step() method have square brackets in it anywhere? Or a get() method of some sort with an index in it.

This error suggests that you're asking for an object in an array or list by providing an index outside of the array bounds. Array bounds start at 0, and end at array.Length - 1.

So a lot of the time this error is caused by looping through objects in an array up to and including array.Length or list.Count

EDIT:

The issue appears to be here (like you suggested):

//Enable the new body nBody.Enabled = true; //Disable the current body mBody.Enabled = false; //Copy the current body's attributes to the new one nBody.SetTransform(mBody.Position, mBody.Rotation); nBody.LinearVelocity = mBody.LinearVelocity; nBody.AngularVelocity = mBody.AngularVelocity; 

I was looking at the code for the .Enabled setter in body.cs in Farseer -- I haven't used Farseer personally so I don't know the exact details of the implementation, but it does a lot of disposing and destroying things when you set enabled to false. I would recommend just rearranging your code like this and giving it a go:

//Enable the new body nBody.Enabled = true; //Copy the current body's attributes to the new one nBody.SetTransform(mBody.Position, mBody.Rotation); nBody.LinearVelocity = mBody.LinearVelocity; nBody.AngularVelocity = mBody.AngularVelocity; //Disable the current body mBody.Enabled = false; mBody = nBody; 
Source Link
Suds
  • 837
  • 2
  • 8
  • 13

Does the erroneous line in your World.step() method have square brackets in it anywhere? Or a get() method of some sort with an index in it.

This error suggests that you're asking for an object in an array or list by providing an index outside of the array bounds. Array bounds start at 0, and end at array.Length - 1.

So a lot of the time this error is caused by looping through objects in an array up to and including array.Length or list.Count

If you can post your World.step() method, I can probably narrow it down a bit more for you.