workaround for a irregularity/bug in physics system (happens very seldom, just 1...
authorErwin Coumans <blender@erwincoumans.com>
Thu, 22 Jun 2006 01:10:50 +0000 (01:10 +0000)
committerErwin Coumans <blender@erwincoumans.com>
Thu, 22 Jun 2006 01:10:50 +0000 (01:10 +0000)
extern/bullet/Bullet/CollisionDispatch/CollisionDispatcher.cpp
extern/bullet/Bullet/CollisionDispatch/CollisionObject.cpp
extern/bullet/Bullet/CollisionDispatch/CollisionObject.h
extern/bullet/Bullet/CollisionDispatch/CollisionWorld.cpp
extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp
source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp

index ba2859e77d8fcf94565d6e0dce13be535533dbae..5749db20a0504af9bd9b856e7ee5e09a505b3c3b 100644 (file)
@@ -243,10 +243,14 @@ CollisionAlgorithm* CollisionDispatcher::InternalFindAlgorithm(BroadphaseProxy&
 
 bool   CollisionDispatcher::NeedsResponse(const  CollisionObject& colObj0,const CollisionObject& colObj1)
 {
+
+       
        //here you can do filtering
        bool hasResponse = 
                (!(colObj0.m_collisionFlags & CollisionObject::noContactResponse)) &&
                (!(colObj1.m_collisionFlags & CollisionObject::noContactResponse));
+       hasResponse = hasResponse &&
+               (colObj0.IsActive() || colObj1.IsActive());
        return hasResponse;
 }
 
@@ -264,8 +268,8 @@ bool        CollisionDispatcher::NeedsCollision(BroadphaseProxy& proxy0,BroadphaseProxy
        if ((body0->m_collisionFlags & CollisionObject::isStatic) && 
                (body1->m_collisionFlags & CollisionObject::isStatic))
                needsCollision = false;
-       
-       if ((body0->GetActivationState() == 2) &&(body1->GetActivationState() == 2))
+               
+       if ((!body0->IsActive()) && (!body1->IsActive()))
                needsCollision = false;
        
        return needsCollision ;
index ab0fea21605cbd41363b03d5f7a261a69134fe0b..056dce59856f0a4d2816fa469bd804d585c10baf 100644 (file)
@@ -29,7 +29,7 @@ CollisionObject::CollisionObject()
 
 void CollisionObject::SetActivationState(int newState) 
 { 
-       if (m_activationState1 != DISABLE_DEACTIVATION)
+       if ( (m_activationState1 != DISABLE_DEACTIVATION) && (m_activationState1 != DISABLE_SIMULATION))
                m_activationState1 = newState;
 }
 
index 9c4e3f14b4af6d1448eec19466f81b2d2fedd4b1..0c2d0be460ce9055b7a20bd30412a6da095e1416 100644 (file)
@@ -23,6 +23,7 @@ subject to the following restrictions:
 #define ISLAND_SLEEPING 2
 #define WANTS_DEACTIVATION 3
 #define DISABLE_DEACTIVATION 4
+#define DISABLE_SIMULATION 5
 
 struct BroadphaseProxy;
 class  CollisionShape;
@@ -85,6 +86,10 @@ struct       CollisionObject
 
        void    activate();
 
+       inline bool IsActive() const
+       {
+               return ((GetActivationState() != ISLAND_SLEEPING) && (GetActivationState() != DISABLE_SIMULATION));
+       }
 
 
 };
index fb905c31eb41337b4748f6d13489838ad5924caa..e8f73b2cc0784a918044c255b9657c2b4a23ca8b 100644 (file)
@@ -171,6 +171,7 @@ void        CollisionWorld::RemoveCollisionObject(CollisionObject* collisionObject)
                        //
                        GetBroadphase()->CleanProxyFromPairs(bp);
                        GetBroadphase()->DestroyProxy(bp);
+                       collisionObject->m_broadphaseHandle = 0;
                }
        }
 
index f169059cf378152f057e4f52f64b454a6d7dcf1e..d5fd194dd99414ac1e63b3e4f2fd690a3798295e 100644 (file)
@@ -637,7 +637,7 @@ bool        CcdPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
                        CcdPhysicsController* ctrl = m_controllers[k];
                        //              SimdTransform predictedTrans;
                        RigidBody* body = ctrl->GetRigidBody();
-                       if (body->GetActivationState() != ISLAND_SLEEPING)
+                       if (body->IsActive())
                        {
                                if (!body->IsStatic())
                                {
@@ -694,14 +694,17 @@ bool      CcdPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
                {
                        TypedConstraint* constraint = m_constraints[i];
 
-                       const CollisionObject* colObj0 = &constraint->GetRigidBodyA();
-                       const CollisionObject* colObj1 = &constraint->GetRigidBodyB();
+                       const RigidBody* colObj0 = &constraint->GetRigidBodyA();
+                       const RigidBody* colObj1 = &constraint->GetRigidBodyB();
                        
                        if (((colObj0) && ((colObj0)->mergesSimulationIslands())) &&
                                                ((colObj1) && ((colObj1)->mergesSimulationIslands())))
                        {
-                               GetDispatcher()->GetUnionFind().unite((colObj0)->m_islandTag1,
-                                       (colObj1)->m_islandTag1);
+                               if (colObj0->IsActive() || colObj1->IsActive())
+                               {
+                                       GetDispatcher()->GetUnionFind().unite((colObj0)->m_islandTag1,
+                                               (colObj1)->m_islandTag1);
+                               }
                        }
                }
        }
@@ -862,7 +865,8 @@ bool        CcdPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
 
                                        SimdTransform predictedTrans;
                                        RigidBody* body = ctrl->GetRigidBody();
-                                       if (body->GetActivationState() != ISLAND_SLEEPING)
+                                       
+                                       if (body->IsActive())
                                        {
 
                                                if (!body->IsStatic())
@@ -1659,9 +1663,27 @@ void     CcdPhysicsEnvironment::UpdateAabbs(float        timeStep)
                                                }
                                        }
 
-                                       scene->SetAabb(bp,minAabb,maxAabb);
-
+                       
+                                       if ( (maxAabb-minAabb).length2() < 1e12f)
+                                       {
+                                               scene->SetAabb(bp,minAabb,maxAabb);
+                                       } else
+                                       {
+                                               //something went wrong, investigate
+                                               //removeCcdPhysicsController(ctrl);
+                                               body->SetActivationState(DISABLE_SIMULATION);
 
+                                               static bool reportMe = true;
+                                               if (reportMe)
+                                               {
+                                                       reportMe = false;
+                                                       printf("Overflow in AABB, object removed from simulation \n");
+                                                       printf("If you can reproduce this, please email bugs@continuousphysics.com\n");
+                                                       printf("Please include above information, your Platform, version of OS.\n");
+                                                       printf("Thanks.\n");
+                                               }
+                                               
+                                       }
 
                                }
                        }
index c974b9b6828b33c33a57a28221d8f83b276c2650..49e0e7953cbe7031a1c787200d1410ab4046e16e 100644 (file)
@@ -144,10 +144,12 @@ void      KX_BulletPhysicsController::setRigidBody(bool rigid)
 
 void   KX_BulletPhysicsController::SuspendDynamics()
 {
+       GetRigidBody()->SetActivationState(DISABLE_SIMULATION);
 
 }
 void   KX_BulletPhysicsController::RestoreDynamics()
 {
+       GetRigidBody()->SetActivationState(ACTIVE_TAG);
 }
 
 SG_Controller* KX_BulletPhysicsController::GetReplica(class SG_Node* destnode)
index f169059cf378152f057e4f52f64b454a6d7dcf1e..d5fd194dd99414ac1e63b3e4f2fd690a3798295e 100644 (file)
@@ -637,7 +637,7 @@ bool        CcdPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
                        CcdPhysicsController* ctrl = m_controllers[k];
                        //              SimdTransform predictedTrans;
                        RigidBody* body = ctrl->GetRigidBody();
-                       if (body->GetActivationState() != ISLAND_SLEEPING)
+                       if (body->IsActive())
                        {
                                if (!body->IsStatic())
                                {
@@ -694,14 +694,17 @@ bool      CcdPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
                {
                        TypedConstraint* constraint = m_constraints[i];
 
-                       const CollisionObject* colObj0 = &constraint->GetRigidBodyA();
-                       const CollisionObject* colObj1 = &constraint->GetRigidBodyB();
+                       const RigidBody* colObj0 = &constraint->GetRigidBodyA();
+                       const RigidBody* colObj1 = &constraint->GetRigidBodyB();
                        
                        if (((colObj0) && ((colObj0)->mergesSimulationIslands())) &&
                                                ((colObj1) && ((colObj1)->mergesSimulationIslands())))
                        {
-                               GetDispatcher()->GetUnionFind().unite((colObj0)->m_islandTag1,
-                                       (colObj1)->m_islandTag1);
+                               if (colObj0->IsActive() || colObj1->IsActive())
+                               {
+                                       GetDispatcher()->GetUnionFind().unite((colObj0)->m_islandTag1,
+                                               (colObj1)->m_islandTag1);
+                               }
                        }
                }
        }
@@ -862,7 +865,8 @@ bool        CcdPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
 
                                        SimdTransform predictedTrans;
                                        RigidBody* body = ctrl->GetRigidBody();
-                                       if (body->GetActivationState() != ISLAND_SLEEPING)
+                                       
+                                       if (body->IsActive())
                                        {
 
                                                if (!body->IsStatic())
@@ -1659,9 +1663,27 @@ void     CcdPhysicsEnvironment::UpdateAabbs(float        timeStep)
                                                }
                                        }
 
-                                       scene->SetAabb(bp,minAabb,maxAabb);
-
+                       
+                                       if ( (maxAabb-minAabb).length2() < 1e12f)
+                                       {
+                                               scene->SetAabb(bp,minAabb,maxAabb);
+                                       } else
+                                       {
+                                               //something went wrong, investigate
+                                               //removeCcdPhysicsController(ctrl);
+                                               body->SetActivationState(DISABLE_SIMULATION);
 
+                                               static bool reportMe = true;
+                                               if (reportMe)
+                                               {
+                                                       reportMe = false;
+                                                       printf("Overflow in AABB, object removed from simulation \n");
+                                                       printf("If you can reproduce this, please email bugs@continuousphysics.com\n");
+                                                       printf("Please include above information, your Platform, version of OS.\n");
+                                                       printf("Thanks.\n");
+                                               }
+                                               
+                                       }
 
                                }
                        }