forked from bartvdbraak/blender
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().
This commit is contained in:
parent
8d42e7b20d
commit
60c8c130fe
@ -342,7 +342,6 @@ bool KX_ConstraintActuator::Update(double curtime, bool frame)
|
|||||||
KX_GameObject *parent = obj->GetParent();
|
KX_GameObject *parent = obj->GetParent();
|
||||||
if (parent) {
|
if (parent) {
|
||||||
spc = parent->GetPhysicsController();
|
spc = parent->GetPhysicsController();
|
||||||
parent->Release();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KX_RayCast::Callback<KX_ConstraintActuator> callback(this,dynamic_cast<PHY_IPhysicsController*>(spc));
|
KX_RayCast::Callback<KX_ConstraintActuator> callback(this,dynamic_cast<PHY_IPhysicsController*>(spc));
|
||||||
|
@ -307,9 +307,6 @@ KX_GameObject* KX_GameObject::GetParent()
|
|||||||
result = (KX_GameObject*)node->GetSGClientObject();
|
result = (KX_GameObject*)node->GetSGClientObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result)
|
|
||||||
result->AddRef();
|
|
||||||
|
|
||||||
return result;
|
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* self = static_cast<KX_GameObject*>(self_v);
|
||||||
KX_GameObject* parent = self->GetParent();
|
KX_GameObject* parent = self->GetParent();
|
||||||
if (parent) {
|
if (parent) {
|
||||||
parent->Release(); /* self->GetParent() AddRef's */
|
|
||||||
return parent->GetProxy();
|
return parent->GetProxy();
|
||||||
}
|
}
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
|
@ -265,9 +265,6 @@ bool KX_RaySensor::Evaluate()
|
|||||||
if (!spc && parent)
|
if (!spc && parent)
|
||||||
spc = parent->GetPhysicsController();
|
spc = parent->GetPhysicsController();
|
||||||
|
|
||||||
if (parent)
|
|
||||||
parent->Release();
|
|
||||||
|
|
||||||
|
|
||||||
PHY_IPhysicsEnvironment* physics_environment = this->m_scene->GetPhysicsEnvironment();
|
PHY_IPhysicsEnvironment* physics_environment = this->m_scene->GetPhysicsEnvironment();
|
||||||
|
|
||||||
|
@ -575,9 +575,6 @@ KX_GameObject* KX_Scene::AddNodeReplicaObject(class SG_IObject* node, class CVal
|
|||||||
newctrl->SetNewClientInfo(newobj->getClientInfo());
|
newctrl->SetNewClientInfo(newobj->getClientInfo());
|
||||||
newobj->SetPhysicsController(newctrl, newobj->IsDynamic());
|
newobj->SetPhysicsController(newctrl, newobj->IsDynamic());
|
||||||
newctrl->PostProcessReplica(motionstate, parentctrl);
|
newctrl->PostProcessReplica(motionstate, parentctrl);
|
||||||
|
|
||||||
if (parent)
|
|
||||||
parent->Release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return newobj;
|
return newobj;
|
||||||
@ -758,8 +755,6 @@ void KX_Scene::DupliGroupRecurse(CValue* obj, int level)
|
|||||||
KX_GameObject *parent = gameobj->GetParent();
|
KX_GameObject *parent = gameobj->GetParent();
|
||||||
if (parent != NULL)
|
if (parent != NULL)
|
||||||
{
|
{
|
||||||
parent->Release(); // GetParent() increased the refcount
|
|
||||||
|
|
||||||
// this object is not a top parent. Either it is the child of another
|
// 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
|
// 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
|
// is added. Or it is the child of an object outside the group and the group
|
||||||
|
@ -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_ClientObjectInfo *my_client_info = static_cast<KX_ClientObjectInfo*>(m_physCtrl->GetNewClientInfo());
|
||||||
KX_GameObject* otherobj = ( client_info ? client_info->m_gameobject : NULL);
|
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
|
// 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
|
// good candidate because they are transient. That must be handled at another level
|
||||||
if (!otherobj ||
|
if (!otherobj ||
|
||||||
|
@ -79,8 +79,6 @@ KX_TrackToActuator::KX_TrackToActuator(SCA_IObject *gameobj,
|
|||||||
m_parentlocalmat = m_parentobj->GetSGNode()->GetLocalOrientation();
|
m_parentlocalmat = m_parentobj->GetSGNode()->GetLocalOrientation();
|
||||||
// use registration mechanism rather than AddRef, it creates zombie objects
|
// use registration mechanism rather than AddRef, it creates zombie objects
|
||||||
m_parentobj->RegisterActuator(this);
|
m_parentobj->RegisterActuator(this);
|
||||||
// GetParent did AddRef, undo here
|
|
||||||
m_parentobj->Release();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3200,8 +3200,6 @@ void CcdPhysicsEnvironment::ConvertObject(KX_GameObject *gameobj, RAS_MeshObject
|
|||||||
{
|
{
|
||||||
delete motionstate;
|
delete motionstate;
|
||||||
shapeInfo->Release();
|
shapeInfo->Release();
|
||||||
if (parent)
|
|
||||||
parent->Release();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3254,8 +3252,6 @@ void CcdPhysicsEnvironment::ConvertObject(KX_GameObject *gameobj, RAS_MeshObject
|
|||||||
shapeInfo->Release();
|
shapeInfo->Release();
|
||||||
// delete motionstate as it's not used
|
// delete motionstate as it's not used
|
||||||
delete motionstate;
|
delete motionstate;
|
||||||
if (parent)
|
|
||||||
parent->Release();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3432,7 +3428,4 @@ void CcdPhysicsEnvironment::ConvertObject(KX_GameObject *gameobj, RAS_MeshObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (parent)
|
|
||||||
parent->Release();
|
|
||||||
}
|
}
|
||||||
|
@ -1375,8 +1375,6 @@ void RAS_OpenGLRasterizer::applyTransform(double* oglmatrix,int objectdrawmode )
|
|||||||
KX_GameObject *parent = gameobj->GetParent();
|
KX_GameObject *parent = gameobj->GetParent();
|
||||||
if (!physics_controller && parent)
|
if (!physics_controller && parent)
|
||||||
physics_controller = parent->GetPhysicsController();
|
physics_controller = parent->GetPhysicsController();
|
||||||
if (parent)
|
|
||||||
parent->Release();
|
|
||||||
|
|
||||||
KX_RayCast::Callback<RAS_OpenGLRasterizer> callback(this, physics_controller, oglmatrix);
|
KX_RayCast::Callback<RAS_OpenGLRasterizer> callback(this, physics_controller, oglmatrix);
|
||||||
if (!KX_RayCast::RayTest(physics_environment, frompoint, topoint, callback))
|
if (!KX_RayCast::RayTest(physics_environment, frompoint, topoint, callback))
|
||||||
|
Loading…
Reference in New Issue
Block a user