Page 1 of 1

Collection was modified; enumeration operation may not...

Posted: Tue Apr 12, 2011 2:34 pm
by Spankenstein
I'm getting the following error:
Collection was modified; enumeration operation may not execute.
when trying to remove an entity from space on an initial collision event:

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);
        }
What is going wrong?

Re: Collection was modified; enumeration operation may not..

Posted: Tue Apr 12, 2011 5:15 pm
by Norbo
In the version you're using, removing entities from within an event handler is not allowed.

v0.15.2 (the latest released stable version) should allow it.

Re: Collection was modified; enumeration operation may not..

Posted: Tue Apr 12, 2011 8:44 pm
by Spankenstein
You're absolutely right, I hadn't updated to the latest version for this project.

Thanks for the help :)