Bugfixes: fix for two memory leaks related to dupligroups,
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 30 Jul 2008 16:15:15 +0000 (16:15 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 30 Jul 2008 16:15:15 +0000 (16:15 +0000)
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/Converter/BL_ActionActuator.cpp
source/gameengine/Converter/BL_ArmatureObject.cpp
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/Ketsji/KX_Scene.cpp
source/gameengine/Ketsji/KX_TrackToActuator.cpp

index 5d6dd694765241c8ab204692a5dd8d94ccee3af6..2ee8b54a0148790f4b81e2f1fff56d9e1b615800 100644 (file)
 
 BL_ActionActuator::~BL_ActionActuator()
 {
-
-       if (m_pose) {
-               free_pose_channels(m_pose);
-               MEM_freeN(m_pose);
-               m_pose = NULL;
-       };
-       
-       if (m_userpose){
-               free_pose_channels(m_userpose);
-               MEM_freeN(m_userpose);
-               m_userpose=NULL;
-       }
-       if (m_blendpose) {
-               free_pose_channels(m_blendpose);
-               MEM_freeN(m_blendpose);
-               m_blendpose = NULL;
-       };
-       
+       if (m_pose)
+               free_pose(m_pose);
+       if (m_userpose)
+               free_pose(m_userpose);
+       if (m_blendpose)
+               free_pose(m_blendpose);
 }
 
 void BL_ActionActuator::ProcessReplica(){
index f73d5b42a016673ed564cd89b1b6c9db327b4118..09f1d9d4d872c876d72c0a9774b53ddccb095c80 100644 (file)
@@ -82,10 +82,8 @@ void BL_ArmatureObject::ProcessReplica(BL_ArmatureObject *replica)
 
 BL_ArmatureObject::~BL_ArmatureObject()
 {
-       if (m_mrdPose){
-               free_pose_channels(m_mrdPose);
-               MEM_freeN(m_mrdPose);
-       }
+       if (m_mrdPose)
+               free_pose(m_mrdPose);
 }
 
 /* note, you can only call this for exisiting Armature objects, and not mix it with other Armatures */
@@ -172,12 +170,13 @@ void BL_ArmatureObject::GetMRDPose(bPose **pose)
        //      copy_pose (&m_mrdPose, m_pose, 0);
        //}
 
-       if (!*pose)
+       if (!*pose) {
                // must duplicate the constraints too otherwise we have corruption in free_pose_channels()
                // because it will free the blender constraints. 
                // Ideally, blender should rememeber that the constraints were not copied so that
                // free_pose_channels() would not free them.
                copy_pose(pose, m_objArma->pose, 1);
+       }
        else
                extract_pose_from_pose(*pose, m_objArma->pose);
 
index 2cc5cfda84c37feaab7900a14007fc6e0d0ebce8..da1767793bb26640b7f83dd99114667589805255 100644 (file)
@@ -628,7 +628,8 @@ BL_Material* ConvertMaterial(
                material->transp = TF_ALPHA;
 
        // always zsort alpha + add
-       if(material->transp == TF_ALPHA || material->transp == TF_ADD || texalpha) {
+       if((material->transp == TF_ALPHA || material->transp == TF_ADD || texalpha)
+               && (material->transp != TF_CLIP)) {
                material->ras_mode |= ALPHA;
                material->ras_mode |= (material->mode & TF_ALPHASORT)? ZSORT: 0;
        }
@@ -1856,7 +1857,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                if (converter->addInitFromFrame)
                        if (!isInActiveLayer)
                                addobj=false;
-                                                                               
+
                if (gameobj&&addobj)
                {
                        MT_Point3 posPrev;                      
index ad476e492d0bf75b191b2722fc1f0b5014a87841..2828663c63df602a45cdd716af1c97212313776d 100644 (file)
@@ -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
index d4bd109de1aba30500b6a3315a5031e0fdb1b2c3..f5b463abf028525de940ccc8658d8737601a5047 100644 (file)
@@ -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<GEN_HashedPtr, void*> *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();
+       }
 }