BulletSim: fix possible race condition where an prim's asset can be requested quicker than the asset fetcher returns and thus falsely reporting that an asset was not fetched and defaulting the assset to a bounding box.
parent
f783b9169f
commit
953090fd62
|
@ -86,7 +86,7 @@ public abstract class BSPhysObject : PhysicsActor
|
||||||
PhysBody = new BulletBody(localID);
|
PhysBody = new BulletBody(localID);
|
||||||
PhysShape = new BulletShape();
|
PhysShape = new BulletShape();
|
||||||
|
|
||||||
LastAssetBuildFailed = false;
|
PrimAssetState = PrimAssetCondition.Unknown;
|
||||||
|
|
||||||
// Default material type. Also sets Friction, Restitution and Density.
|
// Default material type. Also sets Friction, Restitution and Density.
|
||||||
SetMaterial((int)MaterialAttributes.Material.Wood);
|
SetMaterial((int)MaterialAttributes.Material.Wood);
|
||||||
|
@ -133,9 +133,13 @@ public abstract class BSPhysObject : PhysicsActor
|
||||||
// Reference to the physical shape (btCollisionShape) of this object
|
// Reference to the physical shape (btCollisionShape) of this object
|
||||||
public BulletShape PhysShape;
|
public BulletShape PhysShape;
|
||||||
|
|
||||||
// 'true' if the mesh's underlying asset failed to build.
|
// The physical representation of the prim might require an asset fetch.
|
||||||
// This will keep us from looping after the first time the build failed.
|
// The asset state is first 'Unknown' then 'Waiting' then either 'Failed' or 'Fetched'.
|
||||||
public bool LastAssetBuildFailed { get; set; }
|
public enum PrimAssetCondition
|
||||||
|
{
|
||||||
|
Unknown, Waiting, Failed, Fetched
|
||||||
|
}
|
||||||
|
public PrimAssetCondition PrimAssetState { get; set; }
|
||||||
|
|
||||||
// The objects base shape information. Null if not a prim type shape.
|
// The objects base shape information. Null if not a prim type shape.
|
||||||
public PrimitiveBaseShape BaseShape { get; protected set; }
|
public PrimitiveBaseShape BaseShape { get; protected set; }
|
||||||
|
|
|
@ -155,7 +155,7 @@ public class BSPrim : BSPhysObject
|
||||||
public override PrimitiveBaseShape Shape {
|
public override PrimitiveBaseShape Shape {
|
||||||
set {
|
set {
|
||||||
BaseShape = value;
|
BaseShape = value;
|
||||||
LastAssetBuildFailed = false;
|
PrimAssetState = PrimAssetCondition.Unknown;
|
||||||
ForceBodyShapeRebuild(false);
|
ForceBodyShapeRebuild(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -930,11 +930,15 @@ public sealed class BSShapeCollection : IDisposable
|
||||||
return newShape;
|
return newShape;
|
||||||
|
|
||||||
// If this mesh has an underlying asset and we have not failed getting it before, fetch the asset
|
// If this mesh has an underlying asset and we have not failed getting it before, fetch the asset
|
||||||
if (prim.BaseShape.SculptEntry && !prim.LastAssetBuildFailed && prim.BaseShape.SculptTexture != OMV.UUID.Zero)
|
if (prim.BaseShape.SculptEntry
|
||||||
|
&& prim.PrimAssetState != BSPhysObject.PrimAssetCondition.Failed
|
||||||
|
&& prim.PrimAssetState != BSPhysObject.PrimAssetCondition.Waiting
|
||||||
|
&& prim.BaseShape.SculptTexture != OMV.UUID.Zero
|
||||||
|
)
|
||||||
{
|
{
|
||||||
DetailLog("{0},BSShapeCollection.VerifyMeshCreated,fetchAsset,lastFailed={1}", prim.LocalID, prim.LastAssetBuildFailed);
|
DetailLog("{0},BSShapeCollection.VerifyMeshCreated,fetchAsset", prim.LocalID);
|
||||||
// This will prevent looping through this code as we keep trying to get the failed shape
|
// Multiple requestors will know we're waiting for this asset
|
||||||
prim.LastAssetBuildFailed = true;
|
prim.PrimAssetState = BSPhysObject.PrimAssetCondition.Waiting;
|
||||||
|
|
||||||
BSPhysObject xprim = prim;
|
BSPhysObject xprim = prim;
|
||||||
Util.FireAndForget(delegate
|
Util.FireAndForget(delegate
|
||||||
|
@ -945,7 +949,7 @@ public sealed class BSShapeCollection : IDisposable
|
||||||
BSPhysObject yprim = xprim; // probably not necessary, but, just in case.
|
BSPhysObject yprim = xprim; // probably not necessary, but, just in case.
|
||||||
assetProvider(yprim.BaseShape.SculptTexture, delegate(AssetBase asset)
|
assetProvider(yprim.BaseShape.SculptTexture, delegate(AssetBase asset)
|
||||||
{
|
{
|
||||||
bool assetFound = false; // DEBUG DEBUG
|
bool assetFound = false;
|
||||||
string mismatchIDs = String.Empty; // DEBUG DEBUG
|
string mismatchIDs = String.Empty; // DEBUG DEBUG
|
||||||
if (asset != null && yprim.BaseShape.SculptEntry)
|
if (asset != null && yprim.BaseShape.SculptEntry)
|
||||||
{
|
{
|
||||||
|
@ -963,6 +967,10 @@ public sealed class BSShapeCollection : IDisposable
|
||||||
mismatchIDs = yprim.BaseShape.SculptTexture.ToString() + "/" + asset.ID;
|
mismatchIDs = yprim.BaseShape.SculptTexture.ToString() + "/" + asset.ID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (assetFound)
|
||||||
|
yprim.PrimAssetState = BSPhysObject.PrimAssetCondition.Fetched;
|
||||||
|
else
|
||||||
|
yprim.PrimAssetState = BSPhysObject.PrimAssetCondition.Failed;
|
||||||
DetailLog("{0},BSShapeCollection,fetchAssetCallback,found={1},isSculpt={2},ids={3}",
|
DetailLog("{0},BSShapeCollection,fetchAssetCallback,found={1},isSculpt={2},ids={3}",
|
||||||
yprim.LocalID, assetFound, yprim.BaseShape.SculptEntry, mismatchIDs );
|
yprim.LocalID, assetFound, yprim.BaseShape.SculptEntry, mismatchIDs );
|
||||||
|
|
||||||
|
@ -970,6 +978,7 @@ public sealed class BSShapeCollection : IDisposable
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
xprim.PrimAssetState = BSPhysObject.PrimAssetCondition.Failed;
|
||||||
PhysicsScene.Logger.ErrorFormat("{0} Physical object requires asset but no asset provider. Name={1}",
|
PhysicsScene.Logger.ErrorFormat("{0} Physical object requires asset but no asset provider. Name={1}",
|
||||||
LogHeader, PhysicsScene.Name);
|
LogHeader, PhysicsScene.Name);
|
||||||
}
|
}
|
||||||
|
@ -977,7 +986,7 @@ public sealed class BSShapeCollection : IDisposable
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (prim.LastAssetBuildFailed)
|
if (prim.PrimAssetState == BSPhysObject.PrimAssetCondition.Failed)
|
||||||
{
|
{
|
||||||
PhysicsScene.Logger.ErrorFormat("{0} Mesh failed to fetch asset. lID={1}, texture={2}",
|
PhysicsScene.Logger.ErrorFormat("{0} Mesh failed to fetch asset. lID={1}, texture={2}",
|
||||||
LogHeader, prim.LocalID, prim.BaseShape.SculptTexture);
|
LogHeader, prim.LocalID, prim.BaseShape.SculptTexture);
|
||||||
|
|
Loading…
Reference in New Issue