Collection was modified; enumeration operation may not...

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Collection was modified; enumeration operation may not...

Post 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?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

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

Post 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.
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

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

Post by Spankenstein »

You're absolutely right, I hadn't updated to the latest version for this project.

Thanks for the help :)
Post Reply