From 7f170c18bbc3ef3cc8e3b459b8bcc8a789ba0438 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 30 Jul 2008 16:15:15 +0000 Subject: Bugfixes: fix for two memory leaks related to dupligroups, and a missing reference count in the trackto actuator. This showed up as leaked pose data, but actually the whole object was not being freed. --- source/gameengine/Ketsji/KX_Scene.cpp | 9 ++++++++- source/gameengine/Ketsji/KX_TrackToActuator.cpp | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'source/gameengine/Ketsji') diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index ad476e492d0..2828663c63d 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -93,6 +93,9 @@ void* KX_SceneReplicationFunc(SG_IObject* node,void* gameobj,void* scene) { KX_GameObject* replica = ((KX_Scene*)scene)->AddNodeReplicaObject(node,(KX_GameObject*)gameobj); + if(replica) + replica->Release(); + return (void*)replica; } @@ -670,8 +673,12 @@ void KX_Scene::DupliGroupRecurse(CValue* obj, int level) for (oit=m_groupGameObjects.begin(); oit != m_groupGameObjects.end(); oit++) { gameobj = (KX_GameObject*)(*oit); - if (gameobj->GetParent() != NULL) + + 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_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index d4bd109de1a..f5b463abf02 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -195,6 +195,8 @@ void KX_TrackToActuator::ProcessReplica() // the replica is tracking the same object => register it if (m_object) m_object->RegisterActuator(this); + if (m_parentobj) + m_parentobj->AddRef(); SCA_IActuator::ProcessReplica(); } @@ -219,6 +221,14 @@ void KX_TrackToActuator::Relink(GEN_Map *obj_map) m_object = (SCA_IObject*)(*h_obj); m_object->RegisterActuator(this); } + + void **h_parobj = (*obj_map)[m_parentobj]; + if (h_parobj) { + if (m_parentobj) + m_parentobj->Release(); + m_parentobj= (KX_GameObject*)(*h_parobj); + m_parentobj->AddRef(); + } } -- cgit v1.2.3