From 0c971d148cbee691136a8e6f6c0b3dd40ba4e78a Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Wed, 5 Jun 2013 07:09:43 -0700 Subject: BulletSim: fix corner case when rebuilding a compound linkset while a mesh/hull while a mesh or hull is being rebuilt when its asset is fetched. This fixes a 'pure virtual function' crash when changing physical state of complex linksets that include many meshes. --- OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs | 57 +++++++++++++++++++----- 1 file changed, 46 insertions(+), 11 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs index 81edc12..867d2ab 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs @@ -389,9 +389,21 @@ public class BSShapeMesh : BSShape } public override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim) { - // Another reference to this shape is just counted. - IncrementReference(); - return this; + BSShape ret = null; + // If the underlying shape is native, the actual shape has not been build (waiting for asset) + // and we must create a copy of the native shape since they are never shared. + if (physShapeInfo.HasPhysicalShape && physShapeInfo.isNativeShape) + { + // TODO: decide when the native shapes should be freed. Check in Dereference? + ret = BSShapeNative.GetReference(pPhysicsScene, pPrim, BSPhysicsShapeType.SHAPE_BOX, FixedShapeKey.KEY_BOX); + } + else + { + // Another reference to this shape is just counted. + IncrementReference(); + ret = this; + } + return ret; } public override void Dereference(BSScene physicsScene) { @@ -560,9 +572,21 @@ public class BSShapeHull : BSShape } public override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim) { - // Another reference to this shape is just counted. - IncrementReference(); - return this; + BSShape ret = null; + // If the underlying shape is native, the actual shape has not been build (waiting for asset) + // and we must create a copy of the native shape since they are never shared. + if (physShapeInfo.HasPhysicalShape && physShapeInfo.isNativeShape) + { + // TODO: decide when the native shapes should be freed. Check in Dereference? + ret = BSShapeNative.GetReference(pPhysicsScene, pPrim, BSPhysicsShapeType.SHAPE_BOX, FixedShapeKey.KEY_BOX); + } + else + { + // Another reference to this shape is just counted. + IncrementReference(); + ret = this; + } + return ret; } public override void Dereference(BSScene physicsScene) { @@ -1075,12 +1099,23 @@ public class BSShapeGImpact : BSShape (w, iC, i, vC, v) => physicsScene.PE.CreateGImpactShape(w, iC, i, vC, v) ); } - public override BSShape GetReference(BSScene physicsScene, BSPhysObject prim) + public override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim) { - // Calling this reference means we want another handle to an existing shape - // (usually linksets) so return this copy. - IncrementReference(); - return this; + BSShape ret = null; + // If the underlying shape is native, the actual shape has not been build (waiting for asset) + // and we must create a copy of the native shape since they are never shared. + if (physShapeInfo.HasPhysicalShape && physShapeInfo.isNativeShape) + { + // TODO: decide when the native shapes should be freed. Check in Dereference? + ret = BSShapeNative.GetReference(pPhysicsScene, pPrim, BSPhysicsShapeType.SHAPE_BOX, FixedShapeKey.KEY_BOX); + } + else + { + // Another reference to this shape is just counted. + IncrementReference(); + ret = this; + } + return ret; } // Dereferencing a compound shape releases the hold on all the child shapes. public override void Dereference(BSScene physicsScene) -- cgit v1.1