From 60c8c130fed60dc1fe5387b960549385188feadf Mon Sep 17 00:00:00 2001 From: Mitchell Stokes Date: Wed, 30 Apr 2014 18:37:47 -0700 Subject: BGE cleanup: KX_GameObject::GetParent() no longer increases the object's refcount. 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 | 1 - source/gameengine/Ketsji/KX_GameObject.cpp | 4 ---- source/gameengine/Ketsji/KX_RaySensor.cpp | 3 --- source/gameengine/Ketsji/KX_Scene.cpp | 5 ----- source/gameengine/Ketsji/KX_TouchSensor.cpp | 4 ---- source/gameengine/Ketsji/KX_TrackToActuator.cpp | 2 -- source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp | 7 ------- .../Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp | 2 -- 8 files changed, 28 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp index 0c5e21322df..e5662b54b83 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp @@ -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 callback(this,dynamic_cast(spc)); diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 2e39614e7d2..7042e6ed360 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -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(self_v); KX_GameObject* parent = self->GetParent(); if (parent) { - parent->Release(); /* self->GetParent() AddRef's */ return parent->GetProxy(); } Py_RETURN_NONE; diff --git a/source/gameengine/Ketsji/KX_RaySensor.cpp b/source/gameengine/Ketsji/KX_RaySensor.cpp index 84e615b61ab..0f47dfd922b 100644 --- a/source/gameengine/Ketsji/KX_RaySensor.cpp +++ b/source/gameengine/Ketsji/KX_RaySensor.cpp @@ -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(); diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 65f5ff15501..b2dca147f67 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -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 diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index 1b8ef09aec8..5cb1d5f3620 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -208,10 +208,6 @@ bool KX_TouchSensor::BroadPhaseSensorFilterCollision(void*obj1,void*obj2) KX_ClientObjectInfo *my_client_info = static_cast(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 || diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index 44a6e2fd7ee..90b7850946b 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -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(); } } } diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index 966afa0e7f2..3c9c5d0a239 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -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(); } diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index 1227fe892a3..0960fdaab4f 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -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 callback(this, physics_controller, oglmatrix); if (!KX_RayCast::RayTest(physics_environment, frompoint, topoint, callback)) -- cgit v1.2.3