Cannot delete entities from space (0.15.1)

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
steko
Posts: 13
Joined: Thu Oct 14, 2010 12:00 am

Cannot delete entities from space (0.15.1)

Post by steko »

Hi Norbo,

I need some help tracking down the following exceptions:

When I remove an entity with attached eventhandler from it's Space by Space.Remove(), the following error occurs:

"Collection was modified; enumeration operation may not execute."
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Collections.Generic.List`1.Enumerator.MoveNext()
at BEPUphysics.OtherSpaceStages.DeferredEventDispatcher.UpdateStage()
at BEPUphysics.ProcessingStage.Update()
at BEPUphysics.Space.DoTimeStep()
at BEPUphysics.Space.Update(Single dt)
...

If I call CollisionInformation.Events.RemoveAllEvents() before removing the entity from it's space, the following error occurs:

"Object reference not set to an instance of an object."
at BEPUphysics.Collidables.Events.ContactEventManager`1.DispatchEvents()
at BEPUphysics.Collidables.Events.EntryEventManager`1.BEPUphysics.OtherSpaceStages.IDeferredEventCreator.DispatchEvents()
at BEPUphysics.OtherSpaceStages.DeferredEventDispatcher.UpdateStage()
at BEPUphysics.ProcessingStage.Update()
at BEPUphysics.Space.DoTimeStep()
at BEPUphysics.Space.Update(Single dt)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Cannot delete entities from space (0.15.1)

Post by Norbo »

It appears that you are removing the entity and managing the events during a deferred event. That isn't supported at the moment. I'll see if I can allow that or at least make the failure more obvious. In the interim, you can buffer the removal. The Space.SpaceObjectBuffer could do the job, but it flushes at the beginning of the following frame.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Cannot delete entities from space (0.15.1)

Post by Norbo »

I've made a change to the deferred event dispatcher that will be in the next development fork push. Deferred events should be able to support the removal and addition of entities, amongst other things.
steko
Posts: 13
Joined: Thu Oct 14, 2010 12:00 am

Re: Cannot delete entities from space (0.15.1)

Post by steko »

Thanks for clearing that up. You're right. I'm deleting the entity when it's deferred event is fired.
I will check out the SpaceObjectBuffer but it's not a critical issue in our current development state, so I can give it another try when the next BEPU build is online.
Post Reply