Is it safe to remove an entity in this manner?

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
jaja1
Posts: 43
Joined: Sat Nov 15, 2014 3:27 am

Is it safe to remove an entity in this manner?

Post by jaja1 »

Question speaks for itself :)

Code: Select all

Entity.Space.Remove(Entity);
My server has been throwing Null Reference Exceptions on a particular line similar to the above and was wondering if that was the cause. I'm not too sure because sometimes it works and other times it doesn't. Sounds like race conditions I know - but my code is queued properly in a fiber pool and each call to this code is done through a new class instance, so there should be no unexpected access at any point.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Is it safe to remove an entity in this manner?

Post by Norbo »

There is nothing inherently wrong with that snippet in isolation. If it's not a reliable failure, it does indeed sound like a race condition :)
jaja1
Posts: 43
Joined: Sat Nov 15, 2014 3:27 am

Re: Is it safe to remove an entity in this manner?

Post by jaja1 »

Thank you Norbo :)
I think I might have found a logical error in my code that lead to duplicate instances of the the Entity but some of them were not assigned values to :lol:
Post Reply