BGE bug fix (continuation of previous bug fix):

- 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).
This commit is contained in:
Benoit Bolsee 2008-10-17 09:24:35 +00:00
parent c119fb6e51
commit bf0440add8
3 changed files with 10 additions and 5 deletions

@ -116,8 +116,8 @@ public:
/** set the level detection on or off */ /** set the level detection on or off */
void SetLevel(bool lvl); void SetLevel(bool lvl);
void RegisterToManager(); virtual void RegisterToManager();
void UnregisterToManager(); virtual void UnregisterToManager();
virtual float GetNumber(); virtual float GetNumber();

@ -252,8 +252,10 @@ bool KX_NearSensor::NewHandleCollision(void* obj1,void* obj2,const PHY_CollData
client_info->m_gameobject : client_info->m_gameobject :
NULL); NULL);
// these checks are done already in BroadPhaseFilterCollision() // Add the same check as in SCA_ISensor::Activate(),
if (gameobj /*&& (gameobj != parent)*/) // 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)) if (!m_colliders->SearchValue(gameobj))
m_colliders->Add(gameobj->AddRef()); m_colliders->Add(gameobj->AddRef());

@ -184,7 +184,10 @@ bool KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_Coll
client_info->m_gameobject : client_info->m_gameobject :
NULL); 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)) if (!m_colliders->SearchValue(gameobj))
m_colliders->Add(gameobj->AddRef()); m_colliders->Add(gameobj->AddRef());