aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin
diff options
context:
space:
mode:
authorRobert Adams2012-09-28 12:34:50 -0700
committerRobert Adams2012-09-28 12:34:50 -0700
commit76e9cc41bd612035850e105a6fe34f483aab25e7 (patch)
treec1880302adc9cdea27a18203de3c8dec44606bd6 /OpenSim/Region/Physics/BulletSPlugin
parentBulletSim: add separate runtime and taint-time linkset children lists to keep... (diff)
downloadopensim-SC_OLD-76e9cc41bd612035850e105a6fe34f483aab25e7.zip
opensim-SC_OLD-76e9cc41bd612035850e105a6fe34f483aab25e7.tar.gz
opensim-SC_OLD-76e9cc41bd612035850e105a6fe34f483aab25e7.tar.bz2
opensim-SC_OLD-76e9cc41bd612035850e105a6fe34f483aab25e7.tar.xz
BulletSim: remember to release the physical body and shape when a prim is destroyed. This fixes many problems with physical linksets.
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs18
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs14
2 files changed, 16 insertions, 16 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 87ffe3e..a0e627e 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -154,8 +154,9 @@ public sealed class BSPrim : BSPhysObject
154 PhysicsScene.TaintedObject("BSPrim.destroy", delegate() 154 PhysicsScene.TaintedObject("BSPrim.destroy", delegate()
155 { 155 {
156 DetailLog("{0},BSPrim.Destroy,taint,", LocalID); 156 DetailLog("{0},BSPrim.Destroy,taint,", LocalID);
157 // everything in the C# world will get garbage collected. Tell the C++ world to free stuff. 157 // If there are physical body and shape, release my use of same.
158 BulletSimAPI.DestroyObject(PhysicsScene.WorldID, LocalID); 158 PhysicsScene.Shapes.DereferenceBody(BSBody, true, null);
159 PhysicsScene.Shapes.DereferenceShape(BSShape, true, null);
159 }); 160 });
160 } 161 }
161 162
@@ -251,9 +252,6 @@ public sealed class BSPrim : BSPhysObject
251 _rotationalVelocity = OMV.Vector3.Zero; 252 _rotationalVelocity = OMV.Vector3.Zero;
252 253
253 // Zero some other properties directly into the physics engine 254 // Zero some other properties directly into the physics engine
254 BulletSimAPI.SetLinearVelocity2(BSBody.ptr, OMV.Vector3.Zero);
255 BulletSimAPI.SetAngularVelocity2(BSBody.ptr, OMV.Vector3.Zero);
256 BulletSimAPI.SetInterpolationVelocity2(BSBody.ptr, OMV.Vector3.Zero, OMV.Vector3.Zero);
257 BulletSimAPI.ClearForces2(BSBody.ptr); 255 BulletSimAPI.ClearForces2(BSBody.ptr);
258 } 256 }
259 257
@@ -1108,9 +1106,8 @@ public sealed class BSPrim : BSPhysObject
1108 ShapeData shapeData; 1106 ShapeData shapeData;
1109 FillShapeInfo(out shapeData); 1107 FillShapeInfo(out shapeData);
1110 1108
1111 // Undo me from any possible linkset so, if body is rebuilt, the link will get restored. 1109 // If this prim is part of a linkset, we must remove and restore the physical
1112 // NOTE that the new linkset is not set. This saves the handle to the linkset 1110 // links of the body is rebuilt.
1113 // so we can add ourselves back when shape mangling is complete.
1114 bool needToRestoreLinkset = false; 1111 bool needToRestoreLinkset = false;
1115 1112
1116 // Create the correct physical representation for this type of object. 1113 // Create the correct physical representation for this type of object.
@@ -1119,12 +1116,15 @@ public sealed class BSPrim : BSPhysObject
1119 null, delegate(BulletBody dBody) 1116 null, delegate(BulletBody dBody)
1120 { 1117 {
1121 // Called if the current prim body is about to be destroyed. 1118 // Called if the current prim body is about to be destroyed.
1122 // The problem is the constraints for Linksets which need to be updated for the new body. 1119 // Remove all the physical dependencies on the old body.
1123 needToRestoreLinkset = Linkset.RemoveBodyDependencies(this); 1120 needToRestoreLinkset = Linkset.RemoveBodyDependencies(this);
1124 }); 1121 });
1125 1122
1126 if (needToRestoreLinkset) 1123 if (needToRestoreLinkset)
1124 {
1125 // If physical body dependencies were removed, restore them
1127 Linkset.RestoreBodyDependencies(this); 1126 Linkset.RestoreBodyDependencies(this);
1127 }
1128 1128
1129 // Make sure the properties are set on the new object 1129 // Make sure the properties are set on the new object
1130 UpdatePhysicalParameters(); 1130 UpdatePhysicalParameters();
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
index 648910a..dee6243 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
@@ -120,25 +120,25 @@ public class BSShapeCollection : IDisposable
120 // Track another user of a body 120 // Track another user of a body
121 // We presume the caller has allocated the body. 121 // We presume the caller has allocated the body.
122 // Bodies only have one user so the reference count is either 1 or 0. 122 // Bodies only have one user so the reference count is either 1 or 0.
123 public void ReferenceBody(BulletBody shape, bool atTaintTime) 123 public void ReferenceBody(BulletBody body, bool atTaintTime)
124 { 124 {
125 lock (m_collectionActivityLock) 125 lock (m_collectionActivityLock)
126 { 126 {
127 BodyDesc bodyDesc; 127 BodyDesc bodyDesc;
128 if (Bodies.TryGetValue(shape.ID, out bodyDesc)) 128 if (Bodies.TryGetValue(body.ID, out bodyDesc))
129 { 129 {
130 bodyDesc.referenceCount++; 130 bodyDesc.referenceCount++;
131 DetailLog("{0},BSShapeCollection.ReferenceBody,existingBody,ref={1}", shape.ID, bodyDesc.referenceCount); 131 DetailLog("{0},BSShapeCollection.ReferenceBody,existingBody,body={1},ref={2}", body.ID, body, bodyDesc.referenceCount);
132 } 132 }
133 else 133 else
134 { 134 {
135 // New entry 135 // New entry
136 bodyDesc.ptr = shape.ptr; 136 bodyDesc.ptr = body.ptr;
137 bodyDesc.referenceCount = 1; 137 bodyDesc.referenceCount = 1;
138 DetailLog("{0},BSShapeCollection.ReferenceBody,newBody,ref={1}", shape.ID, bodyDesc.referenceCount); 138 DetailLog("{0},BSShapeCollection.ReferenceBody,newBody,ref={1}", body.ID, body, bodyDesc.referenceCount);
139 } 139 }
140 bodyDesc.lastReferenced = System.DateTime.Now; 140 bodyDesc.lastReferenced = System.DateTime.Now;
141 Bodies[shape.ID] = bodyDesc; 141 Bodies[body.ID] = bodyDesc;
142 } 142 }
143} 143}
144 144
@@ -256,7 +256,7 @@ public class BSShapeCollection : IDisposable
256 256
257 // Release the usage of a shape. 257 // Release the usage of a shape.
258 // The collisionObject is released since it is a copy of the real collision shape. 258 // The collisionObject is released since it is a copy of the real collision shape.
259 private void DereferenceShape(BulletShape shape, bool atTaintTime, ShapeDestructionCallback shapeCallback) 259 public void DereferenceShape(BulletShape shape, bool atTaintTime, ShapeDestructionCallback shapeCallback)
260 { 260 {
261 if (shape.ptr == IntPtr.Zero) 261 if (shape.ptr == IntPtr.Zero)
262 return; 262 return;