public static void DeleteAndDisposeAllConstraints(this DynamicsWorld world) { for (int i = 0; i < world.NumConstraints; i++) { TypedConstraint constraint = world.GetConstraint(i); world.DeleteAndDisposeConstraint(constraint); } }
void OnDestroy() { for (int i = 0; i < createdObjs.Count; i++) { Destroy(createdObjs[i]); } createdObjs.Clear(); UnityEngine.Debug.Log("ExitPhysics"); if (World != null) { //remove/dispose constraints int i; for (i = World.NumConstraints - 1; i >= 0; i--) { TypedConstraint constraint = World.GetConstraint(i); World.RemoveConstraint(constraint); constraint.Dispose(); } //remove the rigidbodies from the dynamics world and delete them for (i = World.NumCollisionObjects - 1; i >= 0; i--) { CollisionObject obj = World.CollisionObjectArray[i]; RigidBody body = obj as RigidBody; if (body != null && body.MotionState != null) { body.MotionState.Dispose(); } World.RemoveCollisionObject(obj); obj.Dispose(); } //delete collision shapes foreach (CollisionShape shape in CollisionShapes) { shape.Dispose(); } CollisionShapes.Clear(); World.Dispose(); Broadphase.Dispose(); Dispatcher.Dispose(); CollisionConf.Dispose(); } if (Broadphase != null) { Broadphase.Dispose(); } if (Dispatcher != null) { Dispatcher.Dispose(); } if (CollisionConf != null) { CollisionConf.Dispose(); } }
private static void CleanupConstraints(DynamicsWorld world) { for (int i = world.NumConstraints - 1; i >= 0; i--) { TypedConstraint constraint = world.GetConstraint(i); world.RemoveConstraint(constraint); constraint.Dispose(); } }
public virtual void ExitPhysics() { BulletExampleRunner.Get().ExitPhysics(); UnityEngine.Debug.Log("ExitPhysics"); if (_world != null) { //remove/dispose constraints int i; for (i = _world.NumConstraints - 1; i >= 0; i--) { TypedConstraint constraint = _world.GetConstraint(i); _world.RemoveConstraint(constraint); constraint.Dispose(); } //remove the rigidbodies from the dynamics world and delete them for (i = _world.NumCollisionObjects - 1; i >= 0; i--) { CollisionObject obj = _world.CollisionObjectArray[i]; RigidBody body = obj as RigidBody; if (body != null && body.MotionState != null) { body.MotionState.Dispose(); } _world.RemoveCollisionObject(obj); obj.Dispose(); } //delete collision shapes foreach (CollisionShape shape in CollisionShapes) { shape.Dispose(); } CollisionShapes.Clear(); _world.Dispose(); Broadphase.Dispose(); Dispatcher.Dispose(); CollisionConf.Dispose(); } if (Broadphase != null) { Broadphase.Dispose(); } if (Dispatcher != null) { Dispatcher.Dispose(); } if (CollisionConf != null) { CollisionConf.Dispose(); } }
public void ExitPhysics() { //remove/dispose constraints int i; for (i = World.NumConstraints - 1; i >= 0; i--) { TypedConstraint constraint = World.GetConstraint(i); World.RemoveConstraint(constraint); constraint.Dispose();; } //remove the rigidbodies from the dynamics world and delete them for (i = World.NumCollisionObjects - 1; i >= 0; i--) { CollisionObject obj = World.CollisionObjectArray[i]; RigidBody body = obj as RigidBody; if (body != null && body.MotionState != null) { body.MotionState.Dispose(); } World.RemoveCollisionObject(obj); obj.Dispose(); } //delete collision shapes foreach (CollisionShape shape in CollisionShapes) { shape.Dispose(); } CollisionShapes.Clear(); World.Dispose(); Broadphase.Dispose(); if (Dispatcher != null) { Dispatcher.Dispose(); } }
private static void CleanupConstraints(DynamicsWorld world) { var nonWorldObjects = new HashSet <CollisionObject>(); for (int i = world.NumConstraints - 1; i >= 0; i--) { TypedConstraint constraint = world.GetConstraint(i); world.RemoveConstraint(constraint); if (constraint.RigidBodyA.BroadphaseHandle == null) { nonWorldObjects.Add(constraint.RigidBodyA); } if (constraint.RigidBodyB.BroadphaseHandle == null) { nonWorldObjects.Add(constraint.RigidBodyB); } constraint.Dispose(); } foreach (var obj in nonWorldObjects) { obj.Dispose(); } }
// Disposes of all Unity and Bullet objects and closes the application protected void ExitSimulation() { Debug.Log("Quitting simulation..."); m_quitting = true; // destroy all Unity objects for (int i = 0; i < m_createdObjs.Count; i++) { Destroy(m_createdObjs[i]); } m_createdObjs.Clear(); // destroy all bullet objects if (m_world != null) { //remove/dispose constraints int i; for (i = m_world.NumConstraints - 1; i >= 0; i--) { TypedConstraint constraint = m_world.GetConstraint(i); m_world.RemoveConstraint(constraint); constraint.Dispose(); } //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) { body.MotionState.Dispose(); } m_world.RemoveCollisionObject(obj); obj.Dispose(); } //delete collision shapes foreach (CollisionShape shape in m_collisionShapes) { shape.Dispose(); } m_collisionShapes.Clear(); m_world.Dispose(); m_broadphase.Dispose(); m_colDispatcher.Dispose(); m_colConfig.Dispose(); } if (m_broadphase != null) { m_broadphase.Dispose(); } if (m_colDispatcher != null) { m_colDispatcher.Dispose(); } if (m_colConfig != null) { m_colConfig.Dispose(); } Application.Quit(); }