Page 1 of 1

NullReferenceException from InternalNode.TryToInsert()

Posted: Fri Dec 30, 2016 1:34 am
by nug700
Every so often, randomly with various objects, I get a NullReferenceException from BEPUphysics.BroadPhaseSystems.Hierarchies.InternalNode.TryToInsert(). Happens with code as simple as below:

Code: Select all

Entity Football = new Capsule(new Vector3(0, Offset, 0), 0.095f, 0.026f, 1);
Football.CollisionInformation.CollisionRules.Group = Group;
Football.Gravity = new Vector3(0, -9.81f, 0);
space.Add(Football);
This is not the only object that gives the error. Happens randomly with pretty much any object every so often.

System.NullReferenceException: Object reference not set to an instance of an object.
at BEPUphysics.BroadPhaseSystems.Hierarchies.InternalNode.TryToInsert(LeafNode node, Node& treeNode) in D:\Documents\Visual Studio 2015\Projects\TankFootballServer\TankFootballServer\BEPUphysics\BroadPhaseSystems\Hierarchies\DynamicHierarchyNode.cs:line 199
at BEPUphysics.BroadPhaseSystems.Hierarchies.DynamicHierarchy.Add(BroadPhaseEntry entry) in D:\Documents\Visual Studio 2015\Projects\TankFootballServer\TankFootballServer\BEPUphysics\BroadPhaseSystems\Hierarchies\DynamicHierarchy.cs:line 251
at BEPUphysics.Space.Add(ISpaceObject spaceObject) in D:\Documents\Visual Studio 2015\Projects\TankFootballServer\TankFootballServer\BEPUphysics\Space.cs:line 282

Re: NullReferenceException from InternalNode.TryToInsert()

Posted: Fri Dec 30, 2016 1:43 am
by Norbo
That's a pretty common place for exceptions to happen when adding entities to the Space while the Space is updating. Space.Add/Remove are not safe to call from multiple threads simultaneously, and they're not safe to call while Space.Update is running.

If there is no asynchronous access going on, I'll probably need a repro to figure it out.

Re: NullReferenceException from InternalNode.TryToInsert()

Posted: Fri Dec 30, 2016 1:58 am
by nug700
Yes, The error was caused by adding the entity from another thread. I've changed it so all entities are added on the same thread that's updating it. Thanks!