BulletSim: add some locking for collision lists to prevent collsions
from locking up when running BulletSim on a separate thread.bullet-2.82
parent
c90b986d8b
commit
481b7c71c3
|
@ -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 someone has subscribed for collision events log the collision so it will be reported up
|
||||||
if (SubscribedEvents()) {
|
if (SubscribedEvents()) {
|
||||||
|
lock (PhysScene.CollisionLock)
|
||||||
|
{
|
||||||
CollisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth));
|
CollisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth));
|
||||||
|
}
|
||||||
DetailLog("{0},{1}.Collison.AddCollider,call,with={2},point={3},normal={4},depth={5},colliderMoving={6}",
|
DetailLog("{0},{1}.Collison.AddCollider,call,with={2},point={3},normal={4},depth={5},colliderMoving={6}",
|
||||||
LocalID, TypeName, collidingWith, contactPoint, contactNormal, pentrationDepth, ColliderIsMoving);
|
LocalID, TypeName, collidingWith, contactPoint, contactNormal, pentrationDepth, ColliderIsMoving);
|
||||||
|
|
||||||
|
@ -474,12 +477,14 @@ public abstract class BSPhysObject : PhysicsActor
|
||||||
// Send the collected collisions into the simulator.
|
// Send the collected collisions into the simulator.
|
||||||
// Called at taint time from within the Step() function thus no locking problems
|
// Called at taint time from within the Step() function thus no locking problems
|
||||||
// with CollisionCollection and ObjectsWithNoMoreCollisions.
|
// with CollisionCollection and ObjectsWithNoMoreCollisions.
|
||||||
|
// Called with BSScene.CollisionLock locked to protect the collision lists.
|
||||||
// Return 'true' if there were some actual collisions passed up
|
// Return 'true' if there were some actual collisions passed up
|
||||||
public virtual bool SendCollisions()
|
public virtual bool SendCollisions()
|
||||||
{
|
{
|
||||||
bool ret = true;
|
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);
|
bool force = (CollisionCollection.Count == 0 && CollisionsLastReported.Count != 0);
|
||||||
|
|
||||||
// throttle the collisions to the number of milliseconds specified in the subscription
|
// 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
|
// Note: this is called by the BSPhysObject from invocation via DoPhysicsStep() above so
|
||||||
// this is is under UpdateLock.
|
// this is is under UpdateLock.
|
||||||
public void PostUpdate(BSPhysObject updatee)
|
public void PostUpdate(BSPhysObject updatee)
|
||||||
|
{
|
||||||
|
lock (UpdateLock)
|
||||||
{
|
{
|
||||||
ObjectsWithUpdates.Add(updatee);
|
ObjectsWithUpdates.Add(updatee);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// The simulator thinks it is physics time so return all the collisions and position
|
// The simulator thinks it is physics time so return all the collisions and position
|
||||||
// updates that were collected in actual physics simulation.
|
// 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 (collider.Collide(collidingWith, collidee, collidePoint, collideNormal, penetration))
|
||||||
{
|
{
|
||||||
// If a collision was 'good', remember to send it to the simulator
|
// If a collision was 'good', remember to send it to the simulator
|
||||||
|
lock (CollisionLock)
|
||||||
|
{
|
||||||
ObjectsWithCollisions.Add(collider);
|
ObjectsWithCollisions.Add(collider);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue