NullReferenceException from InternalNode.TryToInsert()

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
nug700
Posts: 9
Joined: Sat Dec 03, 2016 2:34 am

NullReferenceException from InternalNode.TryToInsert()

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

Re: NullReferenceException from InternalNode.TryToInsert()

Post 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.
nug700
Posts: 9
Joined: Sat Dec 03, 2016 2:34 am

Re: NullReferenceException from InternalNode.TryToInsert()

Post 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!
Post Reply