Page 1 of 1

Cannot delete entities from space (0.15.1)

Posted: Tue Mar 22, 2011 12:25 pm
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)

Re: Cannot delete entities from space (0.15.1)

Posted: Tue Mar 22, 2011 5:22 pm
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.

Re: Cannot delete entities from space (0.15.1)

Posted: Tue Mar 22, 2011 6:07 pm
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.

Re: Cannot delete entities from space (0.15.1)

Posted: Tue Mar 22, 2011 7:56 pm
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.