protected virtual void Dispose(bool isdisposing) { if (m_multiBodyConstraintPtr != null) { m_multiBodyConstraintPtr.Dispose(); m_multiBodyConstraintPtr = null; } }
private static void CleanupMultiBodyWorld(MultiBodyDynamicsWorld world) { for (int i = world.NumMultiBodyConstraints - 1; i >= 0; i--) { MultiBodyConstraint multiBodyConstraint = world.GetMultiBodyConstraint(i); world.RemoveMultiBodyConstraint(multiBodyConstraint); multiBodyConstraint.Dispose(); } for (int i = world.NumMultibodies - 1; i >= 0; i--) { MultiBody multiBody = world.GetMultiBody(i); world.RemoveMultiBody(multiBody); multiBody.Dispose(); } }
protected void Dispose(bool disposing) { if (debugType >= BDebug.DebugType.Debug) { Debug.Log("BDynamicsWorld Disposing physics."); } if (PhysicsWorldHelper != null) { PhysicsWorldHelper.m_ddWorld = null; PhysicsWorldHelper.m_world = null; } if (m_world != null) { //remove/dispose constraints int i; if (_ddWorld != null) { if (debugType >= BDebug.DebugType.Debug) { Debug.LogFormat("Removing Constraints {0}", _ddWorld.NumConstraints); } for (i = _ddWorld.NumConstraints - 1; i >= 0; i--) { TypedConstraint constraint = _ddWorld.GetConstraint(i); _ddWorld.RemoveConstraint(constraint); if (constraint.Userobject is BTypedConstraint) { ((BTypedConstraint)constraint.Userobject).m_isInWorld = false; } if (debugType >= BDebug.DebugType.Debug) { Debug.LogFormat("Removed Constaint {0}", constraint.Userobject); } constraint.Dispose(); } } if (debugType >= BDebug.DebugType.Debug) { Debug.LogFormat("Removing Collision Objects {0}", m_world.NumCollisionObjects); } //remove the rigidbodies from the dynamics world and delete them for (i = m_world.NumCollisionObjects - 1; i >= 0; i--) { CollisionObject obj = m_world.CollisionObjectArray[i]; RigidBody body = obj as RigidBody; if (body != null && body.MotionState != null) { Debug.Assert(body.NumConstraintRefs == 0, "Rigid body still had constraints"); body.MotionState.Dispose(); } m_world.RemoveCollisionObject(obj); if (obj.UserObject is BCollisionObject) { ((BCollisionObject)obj.UserObject).isInWorld = false; } if (debugType >= BDebug.DebugType.Debug) { Debug.LogFormat("Removed CollisionObject {0}", obj.UserObject); } obj.Dispose(); } MultiBodyDynamicsWorld _mbdWorld = m_world as MultiBodyDynamicsWorld; if (_mbdWorld != null) { if (debugType >= BDebug.DebugType.Debug) { Debug.LogFormat("Removing MultiBody Constraints {0}", _mbdWorld.NumMultiBodyConstraints); } for (i = _mbdWorld.NumMultiBodyConstraints - 1; i >= 0; i--) { MultiBodyConstraint constraint = _mbdWorld.GetMultiBodyConstraint(i); _mbdWorld.RemoveMultiBodyConstraint(constraint); /* if (constraint.Userobject is BTypedConstraint) ((BTypedConstraint)constraint.Userobject).m_isInWorld = false; * if (debugType >= BDebug.DebugType.Debug) Debug.LogFormat("Removed Constaint {0}", constraint.Userobject);*/ constraint.Dispose(); } if (debugType >= BDebug.DebugType.Debug) { Debug.LogFormat("Removing Multibodies {0}", _mbdWorld.NumMultibodies); } //remove the rigidbodies from the dynamics world and delete them for (i = _mbdWorld.NumMultibodies - 1; i >= 0; i--) { MultiBody mb = _mbdWorld.GetMultiBody(i); _mbdWorld.RemoveMultiBody(mb); if (mb.UserObject is BMultiBody bmb) { bmb.isInWorld = false; } if (debugType >= BDebug.DebugType.Debug) { Debug.LogFormat("Removed CollisionObject {0}", mb.UserObject); } mb.Dispose(); } } if (m_world.DebugDrawer != null) { if (m_world.DebugDrawer is IDisposable) { IDisposable dis = (IDisposable)m_world.DebugDrawer; dis.Dispose(); } } m_world.Dispose(); Broadphase.Dispose(); Dispatcher.Dispose(); CollisionConf.Dispose(); _ddWorld = null; m_world = null; } if (Broadphase != null) { Broadphase.Dispose(); Broadphase = null; } if (Dispatcher != null) { Dispatcher.Dispose(); Dispatcher = null; } if (CollisionConf != null) { CollisionConf.Dispose(); CollisionConf = null; } if (constraintSolver != null) { constraintSolver.Dispose(); constraintSolver = null; } if (softBodyWorldInfo != null) { softBodyWorldInfo.Dispose(); softBodyWorldInfo = null; } _isDisposed = true; singleton = null; }
public virtual void exitPhysics() { removePickingConstraint(); //cleanup in the reverse order of creation/initialization //remove the rigidbodies from the dynamics world and delete them if (m_dynamicsWorld == null) { int i; for (i = m_dynamicsWorld.NumConstraints - 1; i >= 0; i--) { m_dynamicsWorld.RemoveConstraint(m_dynamicsWorld.GetConstraint(i)); } for (i = m_dynamicsWorld.NumMultiBodyConstraints - 1; i >= 0; i--) { MultiBodyConstraint mbc = m_dynamicsWorld.GetMultiBodyConstraint(i); m_dynamicsWorld.RemoveMultiBodyConstraint(mbc); mbc.Dispose(); } for (i = m_dynamicsWorld.NumMultibodies - 1; i >= 0; i--) { MultiBody mb = m_dynamicsWorld.GetMultiBody(i); m_dynamicsWorld.RemoveMultiBody(mb); mb.Dispose(); } for (i = m_dynamicsWorld.NumCollisionObjects - 1; i >= 0; i--) { CollisionObject obj = m_dynamicsWorld.CollisionObjectArray[i]; RigidBody body = RigidBody.Upcast(obj); if (body != null && body.MotionState != null) { body.MotionState.Dispose(); } m_dynamicsWorld.RemoveCollisionObject(obj); obj.Dispose(); } } //delete collision shapes for (int j = 0; j < m_collisionShapes.Count; j++) { CollisionObject shape = m_collisionShapes[j]; shape.Dispose(); } m_collisionShapes.Clear(); m_dynamicsWorld.Dispose(); m_dynamicsWorld = null; m_solver.Dispose(); m_solver = null; m_broadphase.Dispose(); m_broadphase = null; m_dispatcher.Dispose(); m_dispatcher = null; m_pairCache.Dispose(); m_pairCache = null; //m_filterCallback.Dispose(); //m_filterCallback = null; m_collisionConfiguration.Dispose(); m_collisionConfiguration = null; }
public override void ExitPhysics() { if (m_inverseModel != null) { Debug.Log("Dispose inverse model " + m_inverseModel.NumBodies); m_inverseModel.Dispose(); } Debug.Log("InverseDynamicsExitPhysics"); //cleanup in the reverse order of creation/initialization //remove the rigidbodies from the dynamics world and delete them if (m_dynamicsWorld == null) { int i; for (i = m_dynamicsWorld.NumConstraints - 1; i >= 0; i--) { TypedConstraint tc = m_dynamicsWorld.GetConstraint(i); m_dynamicsWorld.RemoveConstraint(tc); tc.Dispose(); } for (i = m_dynamicsWorld.NumMultiBodyConstraints - 1; i >= 0; i--) { MultiBodyConstraint mbc = m_dynamicsWorld.GetMultiBodyConstraint(i); m_dynamicsWorld.RemoveMultiBodyConstraint(mbc); mbc.Dispose(); } for (i = m_dynamicsWorld.NumMultibodies - 1; i >= 0; i--) { MultiBody mb = m_dynamicsWorld.GetMultiBody(i); m_dynamicsWorld.RemoveMultiBody(mb); mb.Dispose(); } for (i = m_dynamicsWorld.NumCollisionObjects - 1; i >= 0; i--) { CollisionObject obj = m_dynamicsWorld.CollisionObjectArray[i]; RigidBody body = RigidBody.Upcast(obj); if (body != null && body.MotionState != null) { body.MotionState.Dispose(); } m_dynamicsWorld.RemoveCollisionObject(obj); obj.Dispose(); } } if (m_multiBody != null) { m_multiBody.Dispose(); } //delete collision shapes for (int j = 0; j < CollisionShapes.Count; j++) { CollisionShape shape = CollisionShapes[j]; shape.Dispose(); } CollisionShapes.Clear(); m_dynamicsWorld.Dispose(); m_dynamicsWorld = null; m_solver.Dispose(); m_solver = null; Broadphase.Dispose(); Broadphase = null; Dispatcher.Dispose(); Dispatcher = null; m_pairCache.Dispose(); m_pairCache = null; CollisionConf.Dispose(); CollisionConf = null; Debug.Log("After dispose B"); }