BGE bug fix (continuation of previous bug fix):
authorBenoit Bolsee <benoit.bolsee@online.be>
Fri, 17 Oct 2008 09:24:35 +0000 (09:24 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Fri, 17 Oct 2008 09:24:35 +0000 (09:24 +0000)
- Forgot to make SCA_ISensor::UnregisterToManager() virtual to intercept active-inactive transition on collision sensor to clear colliders reference.
- Don't record collision on inactive sensor.
  This situation occurs when an object with an inactive collision sensor collides with an object with an active collision sensor: the collision handler triggers both sensors.
  The result of this bug was pending references that eventually cause temporary memory leak (until the sensor is reactivated).

source/gameengine/GameLogic/SCA_ISensor.h
source/gameengine/Ketsji/KX_NearSensor.cpp
source/gameengine/Ketsji/KX_TouchSensor.cpp

index 0d65270dc7b290e75b656a4ad10e08ffcd535c19..d1872009291a181a9f3e3f74a738c8db3c47f537 100644 (file)
@@ -116,8 +116,8 @@ public:
        /** set the level detection on or off */
        void SetLevel(bool lvl);
 
-       void RegisterToManager();
-       void UnregisterToManager();
+       virtual void RegisterToManager();
+       virtual void UnregisterToManager();
 
        virtual float GetNumber();
 
index 397aedb3fa30a3fb5885af126f488a40144bb3e4..bae87c281238b1a05437722f397d1812e820bd5d 100644 (file)
@@ -252,8 +252,10 @@ bool       KX_NearSensor::NewHandleCollision(void* obj1,void* obj2,const PHY_CollData
                        client_info->m_gameobject :
                        NULL);
        
-       // these checks are done already in BroadPhaseFilterCollision()
-       if (gameobj /*&& (gameobj != parent)*/)
+       // Add the same check as in SCA_ISensor::Activate(), 
+       // we don't want to record collision when the sensor is not active.
+       if (m_links && !m_suspended &&
+               gameobj /* done in BroadPhaseFilterCollision() && (gameobj != parent)*/)
        {
                if (!m_colliders->SearchValue(gameobj))
                        m_colliders->Add(gameobj->AddRef());
index 2802da2723da50ae538679ef754b2e6a5a55267f..1935a0bde3900b8e8364e3b586f78935b07db7cb 100644 (file)
@@ -184,7 +184,10 @@ bool       KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_Coll
                        client_info->m_gameobject : 
                        NULL);
        
-       if (gameobj && (gameobj != parent) && client_info->isActor())
+       // add the same check as in SCA_ISensor::Activate(), 
+       // we don't want to record collision when the sensor is not active.
+       if (m_links && !m_suspended &&
+               gameobj && (gameobj != parent) && client_info->isActor())
        {
                if (!m_colliders->SearchValue(gameobj))
                        m_colliders->Add(gameobj->AddRef());