Commit: 60c8c130fed60dc1fe5387b960549385188feadf
Author: Mitchell Stokes
Date:   Wed Apr 30 18:37:47 2014 -0700
https://developer.blender.org/rB60c8c130fed60dc1fe5387b960549385188feadf

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().

===================================================================

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

===================================================================

diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp 
b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp
index 0c5e213..e5662b5 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<KX_ConstraintActuator> 
callback(this,dynamic_cast<PHY_IPhysicsController*>(spc));
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp 
b/source/gameengine/Ketsji/KX_GameObject.cpp
index 2e39614..7042e6e 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<KX_GameObject*>(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 84e615b..0f47dfd 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 65f5ff1..b2dca14 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 1b8ef09..5cb1d5f 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<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 ||
diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp 
b/source/gameengine/Ketsji/KX_TrackToActuator.cpp
index 44a6e2f..90b7850 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 966afa0..3c9c5d0 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 1227fe8..0960fda 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<RAS_OpenGLRasterizer> 
callback(this, physics_controller, oglmatrix);
                        if (!KX_RayCast::RayTest(physics_environment, 
frompoint, topoint, callback))

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to