Page 1 of 1

NullReferenceException after Space.Remove

Posted: Thu Oct 14, 2010 12:36 am
by steko
hi norbo,

first of all thanks for your great work!
i'm using bepu physics since v0.8 now but recently run into an issue after updating to the latest releases (0.14.x).
when i try to remove an entity that has created a collisionpair i get a nullref exception.
in my scenario (which worked in previous versions) are some boxes and a sphere. when the sphere collides with a box, the box will get removed from the collision space.
on the next scene update, when the collision space's update is called, i get a nullref exception.
isn't this the recommended way to remove entities from the space or am i doing something wrong?


System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="BEPUphysics"
StackTrace:
at BEPUphysics.CollisionPair.UpdateContactManifold(Single dt)
at BEPUphysics.Space.UpdateCollisionDetectionCcd()
at BEPUphysics.Space.UpdateCcd()
at BEPUphysics.Space.UpdateWithInternalTimeSteps(Single timeSinceLastFrame)
at BEPUphysics.Space.Update(Single timeSinceLastFrame)
at BEPUphysics.Space.Update(GameTime gameTime)
...

Re: NullReferenceException after Space.Remove

Posted: Thu Oct 14, 2010 1:11 am
by Norbo
This may be related to the events system change. Removing entities from the space using immediate events has always been unsupported; it's possible that during the upgrade to v0.14.1+ an event handler that used to be deferred is now used with an immediate event. Make sure that the event handlers responsible for doing any entity addition/removal are attached to deferred events (past tense names).

Re: NullReferenceException after Space.Remove

Posted: Thu Oct 14, 2010 1:22 am
by steko
thanks for your fast reply. changing the event handling from CollisionPairTouching to CollisionPairTouched did the trick. :)