diff options
author | Robert Adams | 2012-10-05 15:33:17 -0700 |
---|---|---|
committer | Robert Adams | 2012-10-11 14:01:03 -0700 |
commit | 87825b0abee76c28dcffdaa2c532779b813b6d14 (patch) | |
tree | 1028e20a0c2cd8ddea9a60b0b013fa1db69daa74 /OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | |
parent | Updated Robust.HG.ini.example. Thanks Austin Tate. (diff) | |
download | opensim-SC_OLD-87825b0abee76c28dcffdaa2c532779b813b6d14.zip opensim-SC_OLD-87825b0abee76c28dcffdaa2c532779b813b6d14.tar.gz opensim-SC_OLD-87825b0abee76c28dcffdaa2c532779b813b6d14.tar.bz2 opensim-SC_OLD-87825b0abee76c28dcffdaa2c532779b813b6d14.tar.xz |
BulletSim: Fix crash when linking large physical linksets.
Properly remove and restore linkage constraints when upgrading
a prim's mesh to a hull.
Lots more debug logging.
Definitions and use of Bullet structure dumping.
Centralize detail logging so a Flush() can be added for debugging.
Diffstat (limited to '')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index 399a133..283b601 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | |||
@@ -136,7 +136,21 @@ public class BSShapeCollection : IDisposable | |||
136 | // New entry | 136 | // New entry |
137 | bodyDesc.ptr = body.ptr; | 137 | bodyDesc.ptr = body.ptr; |
138 | bodyDesc.referenceCount = 1; | 138 | bodyDesc.referenceCount = 1; |
139 | DetailLog("{0},BSShapeCollection.ReferenceBody,newBody,ref={1}", body.ID, body, bodyDesc.referenceCount); | 139 | DetailLog("{0},BSShapeCollection.ReferenceBody,newBody,ref={2}", |
140 | body.ID, body, bodyDesc.referenceCount); | ||
141 | BSScene.TaintCallback createOperation = delegate() | ||
142 | { | ||
143 | if (!BulletSimAPI.IsInWorld2(body.ptr)) | ||
144 | { | ||
145 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, body.ptr); | ||
146 | DetailLog("{0},BSShapeCollection.ReferenceBody,addedToWorld,ref={1}", | ||
147 | body.ID, body); | ||
148 | } | ||
149 | }; | ||
150 | if (atTaintTime) | ||
151 | createOperation(); | ||
152 | else | ||
153 | PhysicsScene.TaintedObject("BSShapeCollection.ReferenceBody", createOperation); | ||
140 | } | 154 | } |
141 | bodyDesc.lastReferenced = System.DateTime.Now; | 155 | bodyDesc.lastReferenced = System.DateTime.Now; |
142 | Bodies[body.ID] = bodyDesc; | 156 | Bodies[body.ID] = bodyDesc; |
@@ -160,21 +174,22 @@ public class BSShapeCollection : IDisposable | |||
160 | Bodies[body.ID] = bodyDesc; | 174 | Bodies[body.ID] = bodyDesc; |
161 | DetailLog("{0},BSShapeCollection.DereferenceBody,ref={1}", body.ID, bodyDesc.referenceCount); | 175 | DetailLog("{0},BSShapeCollection.DereferenceBody,ref={1}", body.ID, bodyDesc.referenceCount); |
162 | 176 | ||
163 | // If body is no longer being used, free it -- bodies are never shared. | 177 | // If body is no longer being used, free it -- bodies can never be shared. |
164 | if (bodyDesc.referenceCount == 0) | 178 | if (bodyDesc.referenceCount == 0) |
165 | { | 179 | { |
166 | Bodies.Remove(body.ID); | 180 | Bodies.Remove(body.ID); |
167 | BSScene.TaintCallback removeOperation = delegate() | 181 | BSScene.TaintCallback removeOperation = delegate() |
168 | { | 182 | { |
169 | DetailLog("{0},BSShapeCollection.DereferenceBody,DestroyingBody. ptr={1}", | 183 | DetailLog("{0},BSShapeCollection.DereferenceBody,DestroyingBody. ptr={1}, inTaintTime={2}", |
170 | body.ID, body.ptr.ToString("X")); | 184 | body.ID, body.ptr.ToString("X"), inTaintTime); |
171 | // If the caller needs to know the old body is going away, pass the event up. | 185 | // If the caller needs to know the old body is going away, pass the event up. |
172 | if (bodyCallback != null) bodyCallback(body); | 186 | if (bodyCallback != null) bodyCallback(body); |
173 | 187 | ||
174 | // Zero any reference to the shape so it is not freed when the body is deleted. | ||
175 | BulletSimAPI.SetCollisionShape2(PhysicsScene.World.ptr, body.ptr, IntPtr.Zero); | ||
176 | // It may have already been removed from the world in which case the next is a NOOP. | 188 | // It may have already been removed from the world in which case the next is a NOOP. |
177 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, body.ptr); | 189 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, body.ptr); |
190 | |||
191 | // Zero any reference to the shape so it is not freed when the body is deleted. | ||
192 | BulletSimAPI.SetCollisionShape2(PhysicsScene.World.ptr, body.ptr, IntPtr.Zero); | ||
178 | BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, body.ptr); | 193 | BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, body.ptr); |
179 | }; | 194 | }; |
180 | // If already in taint-time, do the operations now. Otherwise queue for later. | 195 | // If already in taint-time, do the operations now. Otherwise queue for later. |
@@ -208,7 +223,7 @@ public class BSShapeCollection : IDisposable | |||
208 | { | 223 | { |
209 | // There is an existing instance of this mesh. | 224 | // There is an existing instance of this mesh. |
210 | meshDesc.referenceCount++; | 225 | meshDesc.referenceCount++; |
211 | DetailLog("{0},BSShapeColliction.ReferenceShape,existingMesh,key={1},cnt={2}", | 226 | DetailLog("{0},BSShapeCollection.ReferenceShape,existingMesh,key={1},cnt={2}", |
212 | BSScene.DetailLogZero, shape.shapeKey.ToString("X"), meshDesc.referenceCount); | 227 | BSScene.DetailLogZero, shape.shapeKey.ToString("X"), meshDesc.referenceCount); |
213 | } | 228 | } |
214 | else | 229 | else |
@@ -217,7 +232,7 @@ public class BSShapeCollection : IDisposable | |||
217 | meshDesc.ptr = shape.ptr; | 232 | meshDesc.ptr = shape.ptr; |
218 | // We keep a reference to the underlying IMesh data so a hull can be built | 233 | // We keep a reference to the underlying IMesh data so a hull can be built |
219 | meshDesc.referenceCount = 1; | 234 | meshDesc.referenceCount = 1; |
220 | DetailLog("{0},BSShapeColliction.ReferenceShape,newMesh,key={1},cnt={2}", | 235 | DetailLog("{0},BSShapeCollection.ReferenceShape,newMesh,key={1},cnt={2}", |
221 | BSScene.DetailLogZero, shape.shapeKey.ToString("X"), meshDesc.referenceCount); | 236 | BSScene.DetailLogZero, shape.shapeKey.ToString("X"), meshDesc.referenceCount); |
222 | ret = true; | 237 | ret = true; |
223 | } | 238 | } |
@@ -230,7 +245,7 @@ public class BSShapeCollection : IDisposable | |||
230 | { | 245 | { |
231 | // There is an existing instance of this hull. | 246 | // There is an existing instance of this hull. |
232 | hullDesc.referenceCount++; | 247 | hullDesc.referenceCount++; |
233 | DetailLog("{0},BSShapeColliction.ReferenceShape,existingHull,key={1},cnt={2}", | 248 | DetailLog("{0},BSShapeCollection.ReferenceShape,existingHull,key={1},cnt={2}", |
234 | BSScene.DetailLogZero, shape.shapeKey.ToString("X"), hullDesc.referenceCount); | 249 | BSScene.DetailLogZero, shape.shapeKey.ToString("X"), hullDesc.referenceCount); |
235 | } | 250 | } |
236 | else | 251 | else |
@@ -238,7 +253,7 @@ public class BSShapeCollection : IDisposable | |||
238 | // This is a new reference to a hull | 253 | // This is a new reference to a hull |
239 | hullDesc.ptr = shape.ptr; | 254 | hullDesc.ptr = shape.ptr; |
240 | hullDesc.referenceCount = 1; | 255 | hullDesc.referenceCount = 1; |
241 | DetailLog("{0},BSShapeColliction.ReferenceShape,newHull,key={1},cnt={2}", | 256 | DetailLog("{0},BSShapeCollection.ReferenceShape,newHull,key={1},cnt={2}", |
242 | BSScene.DetailLogZero, shape.shapeKey.ToString("X"), hullDesc.referenceCount); | 257 | BSScene.DetailLogZero, shape.shapeKey.ToString("X"), hullDesc.referenceCount); |
243 | ret = true; | 258 | ret = true; |
244 | 259 | ||
@@ -525,7 +540,7 @@ public class BSShapeCollection : IDisposable | |||
525 | DetailLog("{0},BSShapeCollection.CreateGeomHull,create,oldKey={1},newKey={2}", | 540 | DetailLog("{0},BSShapeCollection.CreateGeomHull,create,oldKey={1},newKey={2}", |
526 | prim.LocalID, prim.BSShape.shapeKey.ToString("X"), newHullKey.ToString("X")); | 541 | prim.LocalID, prim.BSShape.shapeKey.ToString("X"), newHullKey.ToString("X")); |
527 | 542 | ||
528 | // Remove usage of the previous shape. Also removes reference to underlying mesh if it is a hull. | 543 | // Remove usage of the previous shape. |
529 | DereferenceShape(prim.BSShape, true, shapeCallback); | 544 | DereferenceShape(prim.BSShape, true, shapeCallback); |
530 | 545 | ||
531 | newShape = CreatePhysicalHull(prim.PhysObjectName, newHullKey, pbs, shapeData.Size, lod); | 546 | newShape = CreatePhysicalHull(prim.PhysObjectName, newHullKey, pbs, shapeData.Size, lod); |
@@ -659,6 +674,7 @@ public class BSShapeCollection : IDisposable | |||
659 | if (pbs.SculptEntry) | 674 | if (pbs.SculptEntry) |
660 | lod = PhysicsScene.SculptLOD; | 675 | lod = PhysicsScene.SculptLOD; |
661 | 676 | ||
677 | // Mega prims usually get more detail because one can interact with shape approximations at this size. | ||
662 | float maxAxis = Math.Max(shapeData.Size.X, Math.Max(shapeData.Size.Y, shapeData.Size.Z)); | 678 | float maxAxis = Math.Max(shapeData.Size.X, Math.Max(shapeData.Size.Y, shapeData.Size.Z)); |
663 | if (maxAxis > PhysicsScene.MeshMegaPrimThreshold) | 679 | if (maxAxis > PhysicsScene.MeshMegaPrimThreshold) |
664 | lod = PhysicsScene.MeshMegaPrimLOD; | 680 | lod = PhysicsScene.MeshMegaPrimLOD; |
@@ -709,13 +725,13 @@ public class BSShapeCollection : IDisposable | |||
709 | { | 725 | { |
710 | bodyPtr = BulletSimAPI.CreateBodyFromShape2(sim.ptr, shape.ptr, | 726 | bodyPtr = BulletSimAPI.CreateBodyFromShape2(sim.ptr, shape.ptr, |
711 | shapeData.ID, shapeData.Position, shapeData.Rotation); | 727 | shapeData.ID, shapeData.Position, shapeData.Rotation); |
712 | // DetailLog("{0},BSShapeCollection.CreateBody,mesh,ptr={1}", prim.LocalID, bodyPtr.ToString("X")); | 728 | DetailLog("{0},BSShapeCollection.CreateBody,mesh,ptr={1}", prim.LocalID, bodyPtr.ToString("X")); |
713 | } | 729 | } |
714 | else | 730 | else |
715 | { | 731 | { |
716 | bodyPtr = BulletSimAPI.CreateGhostFromShape2(sim.ptr, shape.ptr, | 732 | bodyPtr = BulletSimAPI.CreateGhostFromShape2(sim.ptr, shape.ptr, |
717 | shapeData.ID, shapeData.Position, shapeData.Rotation); | 733 | shapeData.ID, shapeData.Position, shapeData.Rotation); |
718 | // DetailLog("{0},BSShapeCollection.CreateBody,ghost,ptr={1}", prim.LocalID, bodyPtr.ToString("X")); | 734 | DetailLog("{0},BSShapeCollection.CreateBody,ghost,ptr={1}", prim.LocalID, bodyPtr.ToString("X")); |
719 | } | 735 | } |
720 | aBody = new BulletBody(shapeData.ID, bodyPtr); | 736 | aBody = new BulletBody(shapeData.ID, bodyPtr); |
721 | 737 | ||
@@ -731,7 +747,8 @@ public class BSShapeCollection : IDisposable | |||
731 | 747 | ||
732 | private void DetailLog(string msg, params Object[] args) | 748 | private void DetailLog(string msg, params Object[] args) |
733 | { | 749 | { |
734 | PhysicsScene.PhysicsLogging.Write(msg, args); | 750 | if (PhysicsScene.PhysicsLogging.Enabled) |
751 | PhysicsScene.DetailLog(msg, args); | ||
735 | } | 752 | } |
736 | } | 753 | } |
737 | } | 754 | } |