BGE cleanup: KX_GameObject::GetParent() no longer increases the object's refcount.
authorMitchell Stokes <mogurijin@gmail.com>
Thu, 1 May 2014 01:37:47 +0000 (18:37 -0700)
committerMitchell Stokes <mogurijin@gmail.com>
Thu, 1 May 2014 01:53:32 +0000 (18:53 -0700)
I'm not sure why this function ever increased the object's refcount. Any
place in the code that calls KX_GameObject::GetParent() has to turn
around and call parent->Release(). Forgetting to call Release() was a
common cause of memory leaks (in fact, KX_SteeringActuator was probably
leaking). If the refcount needs to be increased, the calling code can
handle calling AddRef().

source/gameengine/Ketsji/KX_ConstraintActuator.cpp
source/gameengine/Ketsji/KX_GameObject.cpp
source/gameengine/Ketsji/KX_RaySensor.cpp
source/gameengine/Ketsji/KX_Scene.cpp
source/gameengine/Ketsji/KX_TouchSensor.cpp
source/gameengine/Ketsji/KX_TrackToActuator.cpp
source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp

index 0c5e21322dfc0529098f0c06f722075dfe2cace9..e5662b54b83638212f2d14e59e6eaaa1434eca98 100644 (file)
@@ -342,7 +342,6 @@ bool KX_ConstraintActuator::Update(double curtime, bool frame)
                                        KX_GameObject *parent = obj->GetParent();
                                        if (parent) {
                                                spc = parent->GetPhysicsController();
-                                               parent->Release();
                                        }
                                }
                                KX_RayCast::Callback<KX_ConstraintActuator> callback(this,dynamic_cast<PHY_IPhysicsController*>(spc));
index 2e39614e7d2de3b4b46446d0250ab16d65b1d370..7042e6ed36030435c513ac5f4f1f4e1b0eed09a2 100644 (file)
@@ -306,9 +306,6 @@ KX_GameObject* KX_GameObject::GetParent()
                if (node)
                        result = (KX_GameObject*)node->GetSGClientObject();
        }
-       
-       if (result)
-               result->AddRef();
 
        return result;
        
@@ -2113,7 +2110,6 @@ PyObject *KX_GameObject::pyattr_get_parent(void *self_v, const KX_PYATTRIBUTE_DE
        KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
        KX_GameObject* parent = self->GetParent();
        if (parent) {
-               parent->Release(); /* self->GetParent() AddRef's */
                return parent->GetProxy();
        }
        Py_RETURN_NONE;
index 84e615b61abfb89befe56407b1cfd870960fb3e9..0f47dfd922beb1267c02ca5656af865cb9639420 100644 (file)
@@ -265,9 +265,6 @@ bool KX_RaySensor::Evaluate()
        if (!spc && parent)
                spc = parent->GetPhysicsController();
        
-       if (parent)
-               parent->Release();
-       
 
        PHY_IPhysicsEnvironment* physics_environment = this->m_scene->GetPhysicsEnvironment();
        
index 65f5ff155010f01bddbcd0a028500cb7ca8a9cde..b2dca147f677eaacb1e089e7cd9b3e45dc01048a 100644 (file)
@@ -575,9 +575,6 @@ KX_GameObject* KX_Scene::AddNodeReplicaObject(class SG_IObject* node, class CVal
                newctrl->SetNewClientInfo(newobj->getClientInfo());
                newobj->SetPhysicsController(newctrl, newobj->IsDynamic());
                newctrl->PostProcessReplica(motionstate, parentctrl);
-
-               if (parent)
-                       parent->Release();
        }
 
        return newobj;
@@ -758,8 +755,6 @@ void KX_Scene::DupliGroupRecurse(CValue* obj, int level)
                KX_GameObject *parent = gameobj->GetParent();
                if (parent != NULL)
                {
-                       parent->Release(); // GetParent() increased the refcount
-
                        // this object is not a top parent. Either it is the child of another
                        // object in the group and it will be added automatically when the parent
                        // is added. Or it is the child of an object outside the group and the group
index 1b8ef09aec8033c5507664b057d0bd38765e99ee..5cb1d5f3620c3b09fc9de08d2245e3cbc6666553 100644 (file)
@@ -208,10 +208,6 @@ bool       KX_TouchSensor::BroadPhaseSensorFilterCollision(void*obj1,void*obj2)
        KX_ClientObjectInfo *my_client_info = static_cast<KX_ClientObjectInfo*>(m_physCtrl->GetNewClientInfo());
        KX_GameObject* otherobj = ( client_info ? client_info->m_gameobject : NULL);
 
-       // first, decrement refcount as GetParent() increases it
-       if (myparent)
-               myparent->Release();
-
        // we can only check on persistent characteristic: m_link and m_suspended are not
        // good candidate because they are transient. That must be handled at another level
        if (!otherobj ||
index 44a6e2fd7ee73edeb64c786b96dbe6b204ef49fc..90b7850946b96afee7fb2d5dad4324ea767bea60 100644 (file)
@@ -79,8 +79,6 @@ KX_TrackToActuator::KX_TrackToActuator(SCA_IObject *gameobj,
                                m_parentlocalmat = m_parentobj->GetSGNode()->GetLocalOrientation();
                                // use registration mechanism rather than AddRef, it creates zombie objects
                                m_parentobj->RegisterActuator(this);
-                               // GetParent did AddRef, undo here
-                               m_parentobj->Release();
                        }
                }
        }
index 966afa0e7f26ad71da5f2f8f483a219db4cf925d..3c9c5d0a239c7383f9bcb1f3f173da4143014a70 100644 (file)
@@ -3200,8 +3200,6 @@ void CcdPhysicsEnvironment::ConvertObject(KX_GameObject *gameobj, RAS_MeshObject
        {
                delete motionstate;
                shapeInfo->Release();
-               if (parent)
-                       parent->Release();
                return;
        }
 
@@ -3254,8 +3252,6 @@ void CcdPhysicsEnvironment::ConvertObject(KX_GameObject *gameobj, RAS_MeshObject
                        shapeInfo->Release();
                        // delete motionstate as it's not used
                        delete motionstate;
-                       if (parent)
-                               parent->Release();
                        return;
                }
 
@@ -3432,7 +3428,4 @@ void CcdPhysicsEnvironment::ConvertObject(KX_GameObject *gameobj, RAS_MeshObject
                }
        }
 #endif
-
-       if (parent)
-               parent->Release();
 }
index 1227fe892a376a8b72b15747ca8631fb949b19db..0960fdaab4f656b29c2e089d74b0b4c6c5bc9592 100644 (file)
@@ -1375,8 +1375,6 @@ void RAS_OpenGLRasterizer::applyTransform(double* oglmatrix,int objectdrawmode )
                        KX_GameObject *parent = gameobj->GetParent();
                        if (!physics_controller && parent)
                                physics_controller = parent->GetPhysicsController();
-                       if (parent)
-                               parent->Release();
 
                        KX_RayCast::Callback<RAS_OpenGLRasterizer> callback(this, physics_controller, oglmatrix);
                        if (!KX_RayCast::RayTest(physics_environment, frompoint, topoint, callback))