BulletSim: add some locking for collision lists to prevent collsions

from locking up when running BulletSim on a separate thread.
0.8.0.3
Robert Adams 2014-06-20 21:42:08 -07:00 committed by Justin Clark-Casey
parent 56a3d2f00d
commit 5edffc9ecd
2 changed files with 15 additions and 4 deletions

View File

@ -462,7 +462,10 @@ public abstract class BSPhysObject : PhysicsActor
// If someone has subscribed for collision events log the collision so it will be reported up
if (SubscribedEvents()) {
CollisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth));
lock (PhysScene.CollisionLock)
{
CollisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth));
}
DetailLog("{0},{1}.Collison.AddCollider,call,with={2},point={3},normal={4},depth={5},colliderMoving={6}",
LocalID, TypeName, collidingWith, contactPoint, contactNormal, pentrationDepth, ColliderIsMoving);
@ -474,12 +477,14 @@ public abstract class BSPhysObject : PhysicsActor
// Send the collected collisions into the simulator.
// Called at taint time from within the Step() function thus no locking problems
// with CollisionCollection and ObjectsWithNoMoreCollisions.
// Called with BSScene.CollisionLock locked to protect the collision lists.
// Return 'true' if there were some actual collisions passed up
public virtual bool SendCollisions()
{
bool ret = true;
// If the 'no collision' call, force it to happen right now so quick collision_end
// If no collisions this call but there were collisions last call, force the collision
// event to be happen right now so quick collision_end.
bool force = (CollisionCollection.Count == 0 && CollisionsLastReported.Count != 0);
// throttle the collisions to the number of milliseconds specified in the subscription

View File

@ -705,7 +705,10 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
// this is is under UpdateLock.
public void PostUpdate(BSPhysObject updatee)
{
ObjectsWithUpdates.Add(updatee);
lock (UpdateLock)
{
ObjectsWithUpdates.Add(updatee);
}
}
// The simulator thinks it is physics time so return all the collisions and position
@ -803,7 +806,10 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
if (collider.Collide(collidingWith, collidee, collidePoint, collideNormal, penetration))
{
// If a collision was 'good', remember to send it to the simulator
ObjectsWithCollisions.Add(collider);
lock (CollisionLock)
{
ObjectsWithCollisions.Add(collider);
}
}
}