BulletSim: add some locking for collision lists to prevent collsions
from locking up when running BulletSim on a separate thread.0.8.0.3
parent
56a3d2f00d
commit
5edffc9ecd
|
@ -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()) {
|
||||
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
|
||||
|
|
|
@ -704,9 +704,12 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
|
|||
// Note: this is called by the BSPhysObject from invocation via DoPhysicsStep() above so
|
||||
// this is is under UpdateLock.
|
||||
public void PostUpdate(BSPhysObject updatee)
|
||||
{
|
||||
lock (UpdateLock)
|
||||
{
|
||||
ObjectsWithUpdates.Add(updatee);
|
||||
}
|
||||
}
|
||||
|
||||
// The simulator thinks it is physics time so return all the collisions and position
|
||||
// updates that were collected in actual physics simulation.
|
||||
|
@ -803,9 +806,12 @@ 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
|
||||
lock (CollisionLock)
|
||||
{
|
||||
ObjectsWithCollisions.Add(collider);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue