[Bf-blender-cvs] [7b271d5fc11] blender2.8: Depsgraph: Ensure dependency cycle does not clear runtime memory

Sergey Sharybin noreply at git.blender.org
Wed Nov 7 15:06:55 CET 2018


Commit: 7b271d5fc11ada5d5dbd066f0e4523c33933ef51
Author: Sergey Sharybin
Date:   Wed Nov 7 15:04:08 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB7b271d5fc11ada5d5dbd066f0e4523c33933ef51

Depsgraph: Ensure dependency cycle does not clear runtime memory

If there was a dependency cycle involved, it was possible that pchan
array will be freed before all bones are evaluated. Now clear is
done in a dedicated node, which is never a part of dependency cycle.

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

M	source/blender/blenkernel/BKE_armature.h
M	source/blender/blenkernel/intern/armature_update.c
M	source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc
M	source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc
M	source/blender/depsgraph/intern/depsgraph_type_defines.cc
M	source/blender/depsgraph/intern/depsgraph_types.h

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

diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h
index 6937fdcac59..23a9afbda31 100644
--- a/source/blender/blenkernel/BKE_armature.h
+++ b/source/blender/blenkernel/BKE_armature.h
@@ -253,16 +253,15 @@ void BKE_pose_splineik_evaluate(
         struct Object *ob,
         int rootchan_index);
 
-void BKE_pose_eval_flush(
+void BKE_pose_eval_cleanup(
         struct Depsgraph *depsgraph,
         struct Scene *scene,
         struct Object *ob);
 
-void BKE_pose_eval_proxy_pose_init(struct Depsgraph *depsgraph,
-                                   struct Object *object);
-
-void BKE_pose_eval_proxy_pose_done(struct Depsgraph *depsgraph,
-                                   struct Object *object);
+void BKE_pose_eval_proxy_init(struct Depsgraph *depsgraph,
+                              struct Object *object);
+void BKE_pose_eval_proxy_cleanup(struct Depsgraph *depsgraph,
+                                 struct Object *object);
 
 void BKE_pose_eval_proxy_copy_bone(
         struct Depsgraph *depsgraph,
diff --git a/source/blender/blenkernel/intern/armature_update.c b/source/blender/blenkernel/intern/armature_update.c
index c7c69a74202..2d9e2a0d84b 100644
--- a/source/blender/blenkernel/intern/armature_update.c
+++ b/source/blender/blenkernel/intern/armature_update.c
@@ -577,6 +577,7 @@ BLI_INLINE bPoseChannel *pose_pchan_get_indexed(Object *ob, int pchan_index)
 {
 	bPose *pose = ob->pose;
 	BLI_assert(pose != NULL);
+	BLI_assert(pose->chan_array != NULL);
 	BLI_assert(pchan_index >= 0);
 	BLI_assert(pchan_index < MEM_allocN_len(pose->chan_array) / sizeof(bPoseChannel *));
 	return pose->chan_array[pchan_index];
@@ -745,9 +746,9 @@ void BKE_pose_splineik_evaluate(struct Depsgraph *depsgraph,
 	BKE_splineik_execute_tree(depsgraph, scene, ob, rootchan, ctime);
 }
 
-void BKE_pose_eval_flush(struct Depsgraph *depsgraph,
-                         Scene *scene,
-                         Object *ob)
+void BKE_pose_eval_cleanup(struct Depsgraph *depsgraph,
+                           Scene *scene,
+                           Object *ob)
 {
 	bPose *pose = ob->pose;
 	BLI_assert(pose != NULL);
@@ -764,7 +765,7 @@ void BKE_pose_eval_flush(struct Depsgraph *depsgraph,
 	pose->chan_array = NULL;
 }
 
-void BKE_pose_eval_proxy_pose_init(struct Depsgraph *depsgraph, Object *object)
+void BKE_pose_eval_proxy_init(struct Depsgraph *depsgraph, Object *object)
 {
 	BLI_assert(ID_IS_LINKED(object) && object->proxy_from != NULL);
 	DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
@@ -772,7 +773,7 @@ void BKE_pose_eval_proxy_pose_init(struct Depsgraph *depsgraph, Object *object)
 	pose_pchan_index_create(object->pose);
 }
 
-void BKE_pose_eval_proxy_pose_done(struct Depsgraph *depsgraph, Object *object)
+void BKE_pose_eval_proxy_cleanup(struct Depsgraph *depsgraph, Object *object)
 {
 	BLI_assert(ID_IS_LINKED(object) && object->proxy_from != NULL);
 	DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc
index 202b3951417..88e5ca9346c 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc
@@ -220,12 +220,17 @@ void DepsgraphNodeBuilder::build_rig(Object *object, bool is_object_visible)
 	                                           object_cow),
 	                             DEG_OPCODE_POSE_INIT_IK);
 
+	add_operation_node(&object->id,
+	                   DEG_NODE_TYPE_EVAL_POSE,
+	                   function_bind(BKE_pose_eval_cleanup,
+	                                 _1,
+	                                 scene_cow,
+	                                 object_cow),
+	                   DEG_OPCODE_POSE_CLEANUP);
+
 	op_node = add_operation_node(&object->id,
 	                             DEG_NODE_TYPE_EVAL_POSE,
-	                             function_bind(BKE_pose_eval_flush,
-	                                           _1,
-	                                           scene_cow,
-	                                           object_cow),
+	                             NULL,
 	                             DEG_OPCODE_POSE_DONE);
 	op_node->set_as_exit();
 	/* Bones. */
@@ -323,7 +328,7 @@ void DepsgraphNodeBuilder::build_proxy_rig(Object *object)
 	}
 	op_node = add_operation_node(&object->id,
 	                             DEG_NODE_TYPE_EVAL_POSE,
-	                             function_bind(BKE_pose_eval_proxy_pose_init,
+	                             function_bind(BKE_pose_eval_proxy_init,
 	                                           _1,
 	                                           object_cow),
 	                             DEG_OPCODE_POSE_INIT);
@@ -368,9 +373,13 @@ void DepsgraphNodeBuilder::build_proxy_rig(Object *object)
 	}
 	op_node = add_operation_node(&object->id,
 	                             DEG_NODE_TYPE_EVAL_POSE,
-	                             function_bind(BKE_pose_eval_proxy_pose_done,
+	                             function_bind(BKE_pose_eval_proxy_cleanup,
 	                                           _1,
 	                                           object_cow),
+	                             DEG_OPCODE_POSE_CLEANUP);
+	op_node = add_operation_node(&object->id,
+	                             DEG_NODE_TYPE_EVAL_POSE,
+	                             NULL,
 	                             DEG_OPCODE_POSE_DONE);
 	op_node->set_as_exit();
 }
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc
index 90df53d438f..331b476be2c 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc
@@ -221,8 +221,8 @@ void DepsgraphRelationBuilder::build_ik_pose(Object *object,
 		parchan  = parchan->parent;
 	}
 
-	OperationKey flush_key(&object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE);
-	add_relation(solver_key, flush_key, "PoseEval Result-Bone Link");
+	OperationKey done_key(&object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE);
+	add_relation(solver_key, done_key, "PoseEval Result-Bone Link");
 }
 
 /* Spline IK Eval Steps */
@@ -294,8 +294,8 @@ void DepsgraphRelationBuilder::build_splineik_pose(Object *object,
 		if ((segcount == data->chainlen) || (segcount > 255)) break;  /* 255 is weak */
 	}
 
-	OperationKey flush_key(&object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE);
-	add_relation(solver_key, flush_key, "PoseEval Result-Bone Link");
+	OperationKey done_key(&object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE);
+	add_relation(solver_key, done_key, "PoseEval Result-Bone Link");
 }
 
 /* Pose/Armature Bones Graph */
@@ -306,20 +306,28 @@ void DepsgraphRelationBuilder::build_rig(Object *object)
 	// TODO: selection status?
 	/* Attach links between pose operations. */
 	ComponentKey local_transform(&object->id, DEG_NODE_TYPE_TRANSFORM);
-	OperationKey init_key(&object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT);
-	OperationKey init_ik_key(&object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT_IK);
-	OperationKey flush_key(&object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE);
-	add_relation(local_transform, init_key, "Local Transform -> Pose Init");
-	add_relation(init_key, init_ik_key, "Pose Init -> Pose Init IK");
-	add_relation(init_ik_key, flush_key, "Pose Init IK -> Pose Cleanup");
+	OperationKey pose_init_key(
+	        &object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT);
+	OperationKey pose_init_ik_key(
+	        &object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT_IK);
+	OperationKey pose_cleanup_key(
+	        &object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_CLEANUP);
+	OperationKey pose_done_key(
+	        &object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE);
+	add_relation(
+	        local_transform, pose_init_key, "Local Transform -> Pose Init");
+	add_relation(pose_init_key, pose_init_ik_key, "Pose Init -> Pose Init IK");
+	add_relation(
+	        pose_init_ik_key, pose_done_key, "Pose Init IK -> Pose Cleanup");
 	/* Make sure pose is up-to-date with armature updates. */
 	build_armature(armature);
 	OperationKey armature_key(&armature->id,
 	                          DEG_NODE_TYPE_PARAMETERS,
 	                          DEG_OPCODE_PLACEHOLDER,
 	                          "Armature Eval");
-	add_relation(armature_key, init_key, "Data dependency");
-	/* IK Solvers...
+	add_relation(armature_key, pose_init_key, "Data dependency");
+	/* IK Solvers.
+	 *
 	 * - These require separate processing steps are pose-level
 	 *   to be executed between chains of bones (i.e. once the
 	 *   base transforms of a bunch of bones is done)
@@ -377,15 +385,27 @@ void DepsgraphRelationBuilder::build_rig(Object *object)
 	}
 	/* Links between operations for each bone. */
 	LISTBASE_FOREACH (bPoseChannel *, pchan, &object->pose->chanbase) {
-		OperationKey bone_local_key(&object->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_LOCAL);
-		OperationKey bone_pose_key(&object->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_POSE_PARENT);
-		OperationKey bone_ready_key(&object->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_READY);
-		OperationKey bone_done_key(&object->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_DONE);
+		OperationKey bone_local_key(&object->id,
+		                            DEG_NODE_TYPE_BONE,
+		                            pchan->name,
+		                            DEG_OPCODE_BONE_LOCAL);
+		OperationKey bone_pose_key(&object->id,
+		                           DEG_NODE_TYPE_BONE,
+		                           pchan->name,
+		                           DEG_OPCODE_BONE_POSE_PARENT);
+		OperationKey bone_ready_key(&object->id,
+		                            DEG_NODE_TYPE_BONE,
+		                            pchan->name,
+		                            DEG_OPCODE_BONE_READY);
+		OperationKey bone_done_key(&object->id,
+		                           DEG_NODE_TYPE_BONE,
+		                           pchan->name,
+		                           DEG_OPCODE_BONE_D

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list