[Bf-blender-cvs] [9c02f6b1ed6] blender2.8: Fix (unreported) memleak with legacy IKsolver.

Bastien Montagne noreply at git.blender.org
Tue Oct 2 18:00:51 CEST 2018


Commit: 9c02f6b1ed6fea5352ee161b146abff033a085e4
Author: Bastien Montagne
Date:   Tue Oct 2 17:59:11 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB9c02f6b1ed6fea5352ee161b146abff033a085e4

Fix (unreported) memleak with legacy IKsolver.

Looks like new depsgraph may initialize some IK trees, without ever
executing them (which also frees them with legacy IKSolver code)...

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

M	source/blender/ikplugin/intern/ikplugin_api.c
M	source/blender/ikplugin/intern/iksolver_plugin.c
M	source/blender/ikplugin/intern/iksolver_plugin.h

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

diff --git a/source/blender/ikplugin/intern/ikplugin_api.c b/source/blender/ikplugin/intern/ikplugin_api.c
index d2681440177..80de0beb9f4 100644
--- a/source/blender/ikplugin/intern/ikplugin_api.c
+++ b/source/blender/ikplugin/intern/ikplugin_api.c
@@ -53,8 +53,8 @@ static IKPlugin ikplugin_tab[] = {
 	{
 		iksolver_initialize_tree,
 		iksolver_execute_tree,
-		NULL,
-		NULL,
+		iksolver_release_tree,
+		iksolver_clear_data,
 		NULL,
 		NULL,
 		NULL,
diff --git a/source/blender/ikplugin/intern/iksolver_plugin.c b/source/blender/ikplugin/intern/iksolver_plugin.c
index 9248d85c809..0baaa406201 100644
--- a/source/blender/ikplugin/intern/iksolver_plugin.c
+++ b/source/blender/ikplugin/intern/iksolver_plugin.c
@@ -582,3 +582,27 @@ void iksolver_execute_tree(struct Depsgraph *depsgraph, struct Scene *scene, Obj
 		free_posetree(tree);
 	}
 }
+
+void iksolver_release_tree(struct Scene *UNUSED(scene), struct Object *ob,  float UNUSED(ctime))
+{
+	iksolver_clear_data(ob->pose);
+}
+
+void iksolver_clear_data(bPose *pose)
+{
+	for (bPoseChannel *pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
+		if ((pchan->flag & POSE_IKTREE) == 0)
+			continue;
+
+		while (pchan->iktree.first) {
+			PoseTree *tree = pchan->iktree.first;
+
+			/* stop on the first tree that isn't a standard IK chain */
+			if (tree->type != CONSTRAINT_TYPE_KINEMATIC)
+				break;
+
+			BLI_remlink(&pchan->iktree, tree);
+			free_posetree(tree);
+		}
+	}
+}
diff --git a/source/blender/ikplugin/intern/iksolver_plugin.h b/source/blender/ikplugin/intern/iksolver_plugin.h
index cce9511630f..09eb7139192 100644
--- a/source/blender/ikplugin/intern/iksolver_plugin.h
+++ b/source/blender/ikplugin/intern/iksolver_plugin.h
@@ -45,6 +45,8 @@ void iksolver_initialize_tree(
 void iksolver_execute_tree(
         struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob,
         struct bPoseChannel *pchan_root, float ctime);
+void iksolver_release_tree(struct Scene *scene, struct Object *ob, float ctime);
+void iksolver_clear_data(struct bPose *pose);
 
 #ifdef __cplusplus
 }



More information about the Bf-blender-cvs mailing list