Collection was modified; enumeration operation may not...
Posted: Tue Apr 12, 2011 2:34 pm
I'm getting the following error:
What is going wrong?
when trying to remove an entity from space on an initial collision event:Collection was modified; enumeration operation may not execute.
Code: Select all
protected void Events_InitialCollisionDetected(EntityCollidable info, BroadPhaseEntry entry, INarrowPhasePair pair)
{
Kill();
}
Code: Select all
public override void Kill()
{
isValid = false;
//entity.MotionState = MotionState.DefaultState;
entity.LinearVelocity = new Vector3();
entity.AngularVelocity = new Vector3();
entity.WorldTransform = Matrix.Identity;
game.Octree.RemoveObject(this);
game.Space.Remove(entity);
}