BulletSim: fix bug that caused error (and a crash on 32 bit Linux) when mesh assets weren't already in the cache. Comment cleanups.

integration
Robert Adams 2012-10-22 16:33:21 -07:00
parent 7272a4cae8
commit 14eeb8b31b
8 changed files with 51 additions and 35 deletions

View File

@ -34,6 +34,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin
public abstract class BSConstraint : IDisposable public abstract class BSConstraint : IDisposable
{ {
private static string LogHeader = "[BULLETSIM CONSTRAINT]";
protected BulletSim m_world; protected BulletSim m_world;
protected BulletBody m_body1; protected BulletBody m_body1;
protected BulletBody m_body2; protected BulletBody m_body2;
@ -124,7 +126,7 @@ public abstract class BSConstraint : IDisposable
} }
else else
{ {
m_world.physicsScene.Logger.ErrorFormat("[BULLETSIM CONSTRAINT] CalculateTransforms failed. A={0}, B={1}", Body1.ID, Body2.ID); m_world.physicsScene.Logger.ErrorFormat("{0} CalculateTransforms failed. A={1}, B={2}", LogHeader, Body1.ID, Body2.ID);
} }
} }
return ret; return ret;

View File

@ -464,8 +464,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin
// Set the prim's inertia to zero. The vehicle code handles that and this // Set the prim's inertia to zero. The vehicle code handles that and this
// removes the motion and torque actions introduced by Bullet. // removes the motion and torque actions introduced by Bullet.
Vector3 inertia = Vector3.Zero; Vector3 inertia = Vector3.Zero;
BulletSimAPI.SetMassProps2(Prim.BSBody.ptr, Prim.MassRaw, inertia); // comment out for DEBUG test
BulletSimAPI.UpdateInertiaTensor2(Prim.BSBody.ptr); // BulletSimAPI.SetMassProps2(Prim.BSBody.ptr, Prim.MassRaw, inertia);
// BulletSimAPI.UpdateInertiaTensor2(Prim.BSBody.ptr);
} }
// One step of the vehicle properties for the next 'pTimestep' seconds. // One step of the vehicle properties for the next 'pTimestep' seconds.

View File

@ -165,6 +165,9 @@ public abstract class BSLinkset
bool ret = false; bool ret = false;
lock (m_linksetActivityLock) lock (m_linksetActivityLock)
{ {
if (m_children.Contains(child))
ret = true;
/*
foreach (BSPhysObject bp in m_children) foreach (BSPhysObject bp in m_children)
{ {
if (child.LocalID == bp.LocalID) if (child.LocalID == bp.LocalID)
@ -173,6 +176,7 @@ public abstract class BSLinkset
break; break;
} }
} }
*/
} }
return ret; return ret;
} }
@ -196,21 +200,20 @@ public abstract class BSLinkset
// Called at taint-time! // Called at taint-time!
public abstract bool MakeStatic(BSPhysObject child); public abstract bool MakeStatic(BSPhysObject child);
// If the software is handling the movement of all the objects in a linkset // Called when a parameter update comes from the physics engine for any object
// (like if one doesn't use constraints for static linksets), this is called // of the linkset is received.
// when an update for the root of the linkset is received.
// Called at taint-time!! // Called at taint-time!!
public abstract void UpdateProperties(BSPhysObject physObject); public abstract void UpdateProperties(BSPhysObject physObject);
// Routine used when rebuilding the body of the root of the linkset // Routine used when rebuilding the body of the root of the linkset
// Destroy all the constraints have have been made to root. // Destroy all the constraints have have been made to root.
// This is called when the root body is changing. // This is called when the root body is changing.
// Returns 'true' of something eas actually removed and would need restoring // Returns 'true' of something was actually removed and would need restoring
// Called at taint-time!! // Called at taint-time!!
public abstract bool RemoveBodyDependencies(BSPrim child); public abstract bool RemoveBodyDependencies(BSPrim child);
// Companion to RemoveBodyDependencies(). If RemoveBodyDependencies() returns 'true', // Companion to RemoveBodyDependencies(). If RemoveBodyDependencies() returns 'true',
// this routine will restore the removed constraints. // this routine will restore the removed constraints.
// Called at taint-time!! // Called at taint-time!!
public abstract void RestoreBodyDependencies(BSPrim child); public abstract void RestoreBodyDependencies(BSPrim child);

View File

@ -46,9 +46,8 @@ public class BSLinksetConstraints : BSLinkset
// May be called at runtime or taint-time (just pass the appropriate flag). // May be called at runtime or taint-time (just pass the appropriate flag).
public override void Refresh(BSPhysObject requestor, bool inTaintTime) public override void Refresh(BSPhysObject requestor, bool inTaintTime)
{ {
// If there are no children, not physical or not root, I am not the one that recomputes the constraints // If there are no children or not root, I am not the one that recomputes the constraints
// (For the moment, static linksets do create constraints so remove the test for physical.) if (!HasAnyChildren || !IsRoot(requestor))
if (!HasAnyChildren || /*!requestor.IsPhysical ||*/ !IsRoot(requestor))
return; return;
BSScene.TaintCallback refreshOperation = delegate() BSScene.TaintCallback refreshOperation = delegate()
@ -85,20 +84,10 @@ public class BSLinksetConstraints : BSLinkset
return false; return false;
} }
// If the software is handling the movement of all the objects in a linkset
// (like if one doesn't use constraints for static linksets), this is called
// when an update for the root of the linkset is received.
// Called at taint-time!! // Called at taint-time!!
public override void UpdateProperties(BSPhysObject physObject) public override void UpdateProperties(BSPhysObject updated)
{ {
// The root local properties have been updated. Apply to the children if appropriate. // Nothing to do for constraints on property updates
if (IsRoot(physObject) && HasAnyChildren)
{
if (!physObject.IsPhysical)
{
// TODO: implement software linkset update for static object linksets
}
}
} }
// Routine used when rebuilding the body of the root of the linkset // Routine used when rebuilding the body of the root of the linkset

View File

@ -399,7 +399,7 @@ public sealed class BSPrim : BSPhysObject
{ {
// Done at taint time so we're sure the physics engine is not using the variables // Done at taint time so we're sure the physics engine is not using the variables
// Vehicle code changes the parameters for this vehicle type. // Vehicle code changes the parameters for this vehicle type.
this._vehicle.ProcessTypeChange(type); _vehicle.ProcessTypeChange(type);
}); });
} }
} }
@ -1246,12 +1246,13 @@ public sealed class BSPrim : BSPhysObject
FillShapeInfo(out shapeData); FillShapeInfo(out shapeData);
// If this prim is part of a linkset, we must remove and restore the physical // If this prim is part of a linkset, we must remove and restore the physical
// links of the body is rebuilt. // links if the body is rebuilt.
bool needToRestoreLinkset = false; bool needToRestoreLinkset = false;
// Create the correct physical representation for this type of object. // Create the correct physical representation for this type of object.
// Updates BSBody and BSShape with the new information. // Updates BSBody and BSShape with the new information.
// Ignore 'forceRebuild'. This routine makes the right choices and changes of necessary. // Ignore 'forceRebuild'. This routine makes the right choices and changes of necessary.
// Returns 'true' if either the body or the shape was changed.
PhysicsScene.Shapes.GetBodyAndShape(false, PhysicsScene.World, this, shapeData, BaseShape, PhysicsScene.Shapes.GetBodyAndShape(false, PhysicsScene.World, this, shapeData, BaseShape,
null, delegate(BulletBody dBody) null, delegate(BulletBody dBody)
{ {
@ -1355,7 +1356,7 @@ public sealed class BSPrim : BSPhysObject
DetailLog("{0},BSPrim.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}", DetailLog("{0},BSPrim.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}",
LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity); LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity);
// BulletSimAPI.DumpRigidBody2(Scene.World.Ptr, BSBody.Ptr); BulletSimAPI.DumpRigidBody2(PhysicsScene.World.ptr, BSBody.ptr); // DEBUG DEBUG DEBUG
base.RequestPhysicsterseUpdate(); base.RequestPhysicsterseUpdate();
} }
@ -1368,8 +1369,8 @@ public sealed class BSPrim : BSPhysObject
entprop.Acceleration, entprop.RotationalVelocity); entprop.Acceleration, entprop.RotationalVelocity);
} }
*/ */
// The linkset implimentation might want to know about this.
// The linkset implimentation might want to know about this.
Linkset.UpdateProperties(this); Linkset.UpdateProperties(this);
} }
} }

View File

@ -716,6 +716,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters
} }
catch (Exception e) catch (Exception e)
{ {
DetailLog("{0},BSScene.ProcessTaints,doTaintException,id={1}", DetailLogZero, oneCallback.ident); // DEBUG DEBUG DEBUG
m_log.ErrorFormat("{0}: ProcessTaints: {1}: Exception: {2}", LogHeader, oneCallback.ident, e); m_log.ErrorFormat("{0}: ProcessTaints: {1}: Exception: {2}", LogHeader, oneCallback.ident, e);
} }
} }

View File

@ -36,7 +36,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
{ {
public class BSShapeCollection : IDisposable public class BSShapeCollection : IDisposable
{ {
// private static string LogHeader = "[BULLETSIM SHAPE COLLECTION]"; private static string LogHeader = "[BULLETSIM SHAPE COLLECTION]";
protected BSScene PhysicsScene { get; set; } protected BSScene PhysicsScene { get; set; }
@ -434,16 +434,26 @@ public class BSShapeCollection : IDisposable
ShapeData shapeData, ShapeData.FixedShapeKey shapeKey) ShapeData shapeData, ShapeData.FixedShapeKey shapeKey)
{ {
BulletShape newShape; BulletShape newShape;
// Need to make sure the passed shape information is for the native type.
ShapeData nativeShapeData = shapeData;
nativeShapeData.Type = shapeType;
nativeShapeData.MeshKey = (ulong)shapeKey;
nativeShapeData.HullKey = (ulong)shapeKey;
if (shapeType == ShapeData.PhysicsShapeType.SHAPE_AVATAR) if (shapeType == ShapeData.PhysicsShapeType.SHAPE_AVATAR)
{ {
newShape = new BulletShape( newShape = new BulletShape(
BulletSimAPI.BuildCapsuleShape2(PhysicsScene.World.ptr, 1.0f, 1.0f, shapeData.Scale), BulletSimAPI.BuildCapsuleShape2(PhysicsScene.World.ptr, 1.0f, 1.0f, nativeShapeData.Scale), shapeType);
shapeType); DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", nativeShapeData.ID, nativeShapeData.Scale);
} }
else else
{ {
newShape = new BulletShape(BulletSimAPI.BuildNativeShape2(PhysicsScene.World.ptr, shapeData), shapeType); newShape = new BulletShape(BulletSimAPI.BuildNativeShape2(PhysicsScene.World.ptr, nativeShapeData), shapeType);
}
if (newShape.ptr == IntPtr.Zero)
{
PhysicsScene.Logger.ErrorFormat("{0} BuildPhysicalNativeShape failed. ID={1}, shape={2}",
LogHeader, nativeShapeData.ID, nativeShapeData.Type);
} }
newShape.shapeKey = (System.UInt64)shapeKey; newShape.shapeKey = (System.UInt64)shapeKey;
newShape.isNativeShape = true; newShape.isNativeShape = true;
@ -716,6 +726,8 @@ public class BSShapeCollection : IDisposable
{ {
prim.LastAssetBuildFailed = true; prim.LastAssetBuildFailed = true;
BSPhysObject xprim = prim; BSPhysObject xprim = prim;
DetailLog("{0},BSShapeCollection.VerifyMeshCreated,fetchAsset,lID={1},lastFailed={2}",
LogHeader, shapeData.ID.ToString("X"), prim.LastAssetBuildFailed);
Util.FireAndForget(delegate Util.FireAndForget(delegate
{ {
RequestAssetDelegate assetProvider = PhysicsScene.RequestAssetMethod; RequestAssetDelegate assetProvider = PhysicsScene.RequestAssetMethod;
@ -732,16 +744,25 @@ public class BSShapeCollection : IDisposable
yprim.BaseShape.SculptData = asset.Data; yprim.BaseShape.SculptData = asset.Data;
// This will cause the prim to see that the filler shape is not the right // This will cause the prim to see that the filler shape is not the right
// one and try again to build the object. // one and try again to build the object.
// No race condition with the native sphere setting since the rebuild is at taint time.
yprim.ForceBodyShapeRebuild(false); yprim.ForceBodyShapeRebuild(false);
}); });
} }
}); });
} }
else
{
if (prim.LastAssetBuildFailed)
{
PhysicsScene.Logger.ErrorFormat("{0} Mesh failed to fetch asset. lID={1}, texture={2}",
LogHeader, shapeData.ID, pbs.SculptTexture);
}
}
// While we figure out the real problem, stick a simple native shape on the object. // While we figure out the real problem, stick a simple native shape on the object.
BulletShape fillinShape = BulletShape fillinShape =
BuildPhysicalNativeShape(ShapeData.PhysicsShapeType.SHAPE_SPHERE, shapeData, ShapeData.FixedShapeKey.KEY_SPHERE); BuildPhysicalNativeShape(ShapeData.PhysicsShapeType.SHAPE_BOX, shapeData, ShapeData.FixedShapeKey.KEY_BOX);
return fillinShape; return fillinShape;
} }

View File

@ -201,9 +201,7 @@ public class BSTerrainManager
// If called with a mapInfo in m_heightMaps and there is an existing terrain body, a new // If called with a mapInfo in m_heightMaps and there is an existing terrain body, a new
// terrain shape is created and added to the body. // terrain shape is created and added to the body.
// This call is most often used to update the heightMap and parameters of the terrain. // This call is most often used to update the heightMap and parameters of the terrain.
// The 'doNow' boolean says whether to do all the unmanaged activities right now (like when // (The above does suggest that some simplification/refactoring is in order.)
// calling this routine from initialization or taint-time routines) or whether to delay
// all the unmanaged activities to taint-time.
private void UpdateOrCreateTerrain(uint id, float[] heightMap, Vector3 minCoords, Vector3 maxCoords, bool inTaintTime) private void UpdateOrCreateTerrain(uint id, float[] heightMap, Vector3 minCoords, Vector3 maxCoords, bool inTaintTime)
{ {
DetailLog("{0},BSTerrainManager.UpdateOrCreateTerrain,call,minC={1},maxC={2},inTaintTime={3}", DetailLog("{0},BSTerrainManager.UpdateOrCreateTerrain,call,minC={1},maxC={2},inTaintTime={3}",