BulletSim: fix compound linkset crash by not freeing shape of child prims.

Remove all compilation warnings (mostly 'protected' in sealed classes.)
Add the dynamicAabbEnable parameter to creation of compound shapes.
integration
Robert Adams 2012-11-03 21:08:39 -07:00
parent 894bb4893b
commit 79f7c466a1
6 changed files with 25 additions and 17 deletions

View File

@ -89,7 +89,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
//Angular properties
private Vector3 m_angularMotorDirection = Vector3.Zero; // angular velocity requested by LSL motor
private int m_angularMotorApply = 0; // application frame counter
// private int m_angularMotorApply = 0; // application frame counter
private Vector3 m_angularMotorVelocity = Vector3.Zero; // current angular motor velocity
private float m_angularMotorTimescale = 0; // motor angular velocity ramp up rate
private float m_angularMotorDecayTimescale = 0; // motor angular velocity decay rate
@ -199,7 +199,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
break;
case Vehicle.ANGULAR_MOTOR_DIRECTION:
m_angularMotorDirection = new Vector3(pValue, pValue, pValue);
m_angularMotorApply = 100;
// m_angularMotorApply = 100;
break;
case Vehicle.LINEAR_FRICTION_TIMESCALE:
m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue);
@ -229,7 +229,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
pValue.Y = Math.Max(-12.56f, Math.Min(pValue.Y, 12.56f));
pValue.Z = Math.Max(-12.56f, Math.Min(pValue.Z, 12.56f));
m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
m_angularMotorApply = 100;
// m_angularMotorApply = 100;
break;
case Vehicle.LINEAR_FRICTION_TIMESCALE:
m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);

View File

@ -83,8 +83,8 @@ public sealed class BSLinksetCompound : BSLinkset
public override bool MakeDynamic(BSPhysObject child)
{
bool ret = false;
DetailLog("{0},BSLinksetCompound.MakeDynamic,call,isChild={1}", child.LocalID, HasChild(child));
if (HasChild(child))
DetailLog("{0},BSLinksetCompound.MakeDynamic,call,IsRoot={1}", child.LocalID, IsRoot(child));
if (!IsRoot(child))
{
// Physical children are removed from the world as the shape ofthe root compound
// shape takes over.
@ -103,8 +103,8 @@ public sealed class BSLinksetCompound : BSLinkset
public override bool MakeStatic(BSPhysObject child)
{
bool ret = false;
DetailLog("{0},BSLinksetCompound.MakeStatic,call,hasChild={1}", child.LocalID, HasChild(child));
if (HasChild(child))
DetailLog("{0},BSLinksetCompound.MakeStatic,call,IsRoot={1}", child.LocalID, IsRoot(child));
if (!IsRoot(child))
{
// The non-physical children can come back to life.
BulletSimAPI.RemoveFromCollisionFlags2(child.PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE);
@ -240,6 +240,7 @@ public sealed class BSLinksetCompound : BSLinkset
// A mesh or hull is created because scale is not available on a native shape.
// (TODO: Bullet does have a btScaledCollisionShape. Can that be used?)
BulletShape saveShape = cPrim.PhysShape;
cPrim.PhysShape.ptr = IntPtr.Zero; // Don't let the create free the child's shape
PhysicsScene.Shapes.CreateGeomMeshOrHull(cPrim, null);
BulletShape newShape = cPrim.PhysShape;
cPrim.PhysShape = saveShape;
@ -263,7 +264,7 @@ public sealed class BSLinksetCompound : BSLinkset
float linksetMass = LinksetMass;
LinksetRoot.UpdatePhysicalMassProperties(linksetMass);
// DEBUG: see of inter-linkset collisions are causing problems
// DEBUG: see of inter-linkset collisions are causing problems for constraint linksets.
// BulletSimAPI.SetCollisionFilterMask2(LinksetRoot.BSBody.ptr,
// (uint)CollisionFilterGroups.LinksetFilter, (uint)CollisionFilterGroups.LinksetMask);

View File

@ -703,6 +703,9 @@ public sealed class BSPrim : BSPhysObject
// For good measure, make sure the transform is set through to the motion state
BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
// Center of mass is at the center of the object
BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody.ptr, _position, _orientation);
// A dynamic object has mass
UpdatePhysicalMassProperties(RawMass);

View File

@ -1391,7 +1391,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
// If the local ID is APPLY_TO_NONE, just change the default value
// If the localID is APPLY_TO_ALL change the default value and apply the new value to all the lIDs
// If the localID is a specific object, apply the parameter change to only that object
protected void UpdateParameterObject(ref float defaultLoc, string parm, uint localID, float val)
private void UpdateParameterObject(ref float defaultLoc, string parm, uint localID, float val)
{
List<uint> objectIDs = new List<uint>();
switch (localID)
@ -1416,7 +1416,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
}
// schedule the actual updating of the paramter to when the phys engine is not busy
protected void TaintedUpdateParameter(string parm, List<uint> lIDs, float val)
private void TaintedUpdateParameter(string parm, List<uint> lIDs, float val)
{
float xval = val;
List<uint> xlIDs = lIDs;

View File

@ -38,7 +38,7 @@ public sealed class BSShapeCollection : IDisposable
{
private static string LogHeader = "[BULLETSIM SHAPE COLLECTION]";
protected BSScene PhysicsScene { get; set; }
private BSScene PhysicsScene { get; set; }
private Object m_collectionActivityLock = new Object();
@ -103,11 +103,12 @@ public sealed class BSShapeCollection : IDisposable
{
// Do we have the correct geometry for this type of object?
// Updates prim.BSShape with information/pointers to shape.
// CreateGeom returns 'true' of BSShape as changed to a new shape.
// Returns 'true' of BSShape is changed to a new shape.
bool newGeom = CreateGeom(forceRebuild, prim, shapeCallback);
// If we had to select a new shape geometry for the object,
// rebuild the body around it.
// Updates prim.BSBody with information/pointers to requested body
// Returns 'true' if BSBody was changed.
bool newBody = CreateBody((newGeom || forceRebuild), prim, PhysicsScene.World,
prim.PhysShape, bodyCallback);
ret = newGeom || newBody;
@ -431,6 +432,7 @@ public sealed class BSShapeCollection : IDisposable
return ret;
}
// Create a mesh/hull shape or a native shape if 'nativeShapePossible' is 'true'.
private bool CreateGeomNonSpecial(bool forceRebuild, BSPhysObject prim, ShapeDestructionCallback shapeCallback)
{
bool ret = false;
@ -797,15 +799,17 @@ public sealed class BSShapeCollection : IDisposable
private bool GetReferenceToCompoundShape(BSPhysObject prim, ShapeDestructionCallback shapeCallback)
{
// Remove reference to the old shape
// Don't need to do this as the shape is freed when we create the new root shape below.
// Don't need to do this as the shape is freed when the new root shape is created below.
// DereferenceShape(prim.PhysShape, true, shapeCallback);
BulletShape cShape = new BulletShape(
BulletSimAPI.CreateCompoundShape2(PhysicsScene.World.ptr), ShapeData.PhysicsShapeType.SHAPE_COMPOUND);
BulletSimAPI.CreateCompoundShape2(PhysicsScene.World.ptr, false), ShapeData.PhysicsShapeType.SHAPE_COMPOUND);
// Create the shape for the root prim and add it to the compound shape
CreateGeomNonSpecial(true, prim, null);
// Create the shape for the root prim and add it to the compound shape. Cannot be a native shape.
CreateGeomMeshOrHull(prim, shapeCallback);
BulletSimAPI.AddChildShapeToCompoundShape2(cShape.ptr, prim.PhysShape.ptr, OMV.Vector3.Zero, OMV.Quaternion.Identity);
DetailLog("{0},BSShapeCollection.GetReferenceToCompoundShape,addRootPrim,compShape={1},rootShape={2}",
prim.LocalID, cShape, prim.PhysShape);
prim.PhysShape = cShape;

View File

@ -614,7 +614,7 @@ public static extern bool IsNativeShape2(IntPtr shape);
public static extern IntPtr BuildCapsuleShape2(IntPtr world, float radius, float height, Vector3 scale);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern IntPtr CreateCompoundShape2(IntPtr sim);
public static extern IntPtr CreateCompoundShape2(IntPtr sim, bool enableDynamicAabbTree);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern int GetNumberOfCompoundChildren2(IntPtr cShape);