BulletSim: add locking around Meshmerizer use to eliminate possible race
condition when extracting the convex hulls.user_profiles
parent
5efce21abc
commit
29b3b44fab
|
@ -441,10 +441,14 @@ public class BSShapeMesh : BSShape
|
|||
{
|
||||
BulletShape newShape = new BulletShape();
|
||||
|
||||
IMesh meshData = physicsScene.mesher.CreateMesh(prim.PhysObjectName, pbs, size, lod,
|
||||
IMesh meshData = null;
|
||||
lock (physicsScene.mesher)
|
||||
{
|
||||
meshData = physicsScene.mesher.CreateMesh(prim.PhysObjectName, pbs, size, lod,
|
||||
false, // say it is not physical so a bounding box is not built
|
||||
false // do not cache the mesh and do not use previously built versions
|
||||
);
|
||||
}
|
||||
|
||||
if (meshData != null)
|
||||
{
|
||||
|
@ -576,17 +580,30 @@ public class BSShapeHull : BSShape
|
|||
BulletShape newShape = new BulletShape();
|
||||
newShape.shapeKey = newHullKey;
|
||||
|
||||
IMesh meshData = null;
|
||||
List<List<OMV.Vector3>> allHulls = null;
|
||||
lock (physicsScene.mesher)
|
||||
{
|
||||
// Pass true for physicalness as this prevents the creation of bounding box which is not needed
|
||||
IMesh meshData = physicsScene.mesher.CreateMesh(prim.PhysObjectName, pbs, size, lod, true /* isPhysical */, false /* shouldCache */);
|
||||
meshData = physicsScene.mesher.CreateMesh(prim.PhysObjectName, pbs, size, lod, true /* isPhysical */, false /* shouldCache */);
|
||||
|
||||
// If there is hull data in the mesh asset, build the hull from that
|
||||
// If we should use the asset's hull info, fetch it out of the locked mesher
|
||||
if (meshData != null && BSParam.ShouldUseAssetHulls)
|
||||
{
|
||||
Meshmerizer realMesher = physicsScene.mesher as Meshmerizer;
|
||||
if (realMesher != null)
|
||||
{
|
||||
List<List<OMV.Vector3>> allHulls = realMesher.GetConvexHulls(size);
|
||||
if (allHulls != null)
|
||||
allHulls = realMesher.GetConvexHulls(size);
|
||||
}
|
||||
if (allHulls == null)
|
||||
{
|
||||
physicsScene.DetailLog("{0},BSShapeHull.CreatePhysicalHull,assetHulls,noAssetHull", prim.LocalID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If there is hull data in the mesh asset, build the hull from that
|
||||
if (allHulls != null && BSParam.ShouldUseAssetHulls)
|
||||
{
|
||||
int hullCount = allHulls.Count;
|
||||
int totalVertices = 1; // include one for the count of the hulls
|
||||
|
@ -623,8 +640,7 @@ public class BSShapeHull : BSShape
|
|||
physicsScene.DetailLog("{0},BSShapeHull.CreatePhysicalHull,assetHulls,hulls={1},totVert={2},shape={3}",
|
||||
prim.LocalID, hullCount, totalVertices, newShape);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If no hull specified in the asset and we should use Bullet's HACD approximation...
|
||||
if (!newShape.HasPhysicalShape && BSParam.ShouldUseBulletHACD)
|
||||
{
|
||||
|
@ -655,11 +671,9 @@ public class BSShapeHull : BSShape
|
|||
}
|
||||
physicsScene.DetailLog("{0},BSShapeHull.CreatePhysicalHull,bulletHACD,exit,hasBody={1}", prim.LocalID, newShape.HasPhysicalShape);
|
||||
}
|
||||
// If no hull specified, use our HACD hull approximation.
|
||||
if (!newShape.HasPhysicalShape)
|
||||
{
|
||||
// Build a new hull in the physical world using the C# HACD algorigthm.
|
||||
if (meshData != null)
|
||||
|
||||
// If no other hull specifications, use our HACD hull approximation.
|
||||
if (!newShape.HasPhysicalShape && meshData != null)
|
||||
{
|
||||
if (prim.PrimAssetState == BSPhysObject.PrimAssetCondition.Fetched)
|
||||
{
|
||||
|
@ -768,8 +782,6 @@ public class BSShapeHull : BSShape
|
|||
// create the hull data structure in Bullet
|
||||
newShape = physicsScene.PE.CreateHullShape(physicsScene.World, hullCount, convHulls);
|
||||
}
|
||||
newShape.shapeKey = newHullKey;
|
||||
}
|
||||
return newShape;
|
||||
}
|
||||
// Callback from convex hull creater with a newly created hull.
|
||||
|
|
Loading…
Reference in New Issue