[Bf-blender-cvs] [25ee094] master: Fix T49385: Copy buffer is not from pose mode. Report Error

Sergey Sharybin noreply at git.blender.org
Mon Sep 19 14:17:58 CEST 2016


Commit: 25ee0942266b698363a2fb9f092ca68f58044064
Author: Sergey Sharybin
Date:   Mon Sep 19 14:17:05 2016 +0200
Branches: master
https://developer.blender.org/rB25ee0942266b698363a2fb9f092ca68f58044064

Fix T49385: Copy buffer is not from pose mode. Report Error

Quick fix for now, need to unlock studio here as well.

Proper fix would be to modify API a bit and pass flags which will
prevent expand called on bmain perhaps. But this we should discuss
a bit,

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

M	source/blender/editors/armature/pose_transform.c

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

diff --git a/source/blender/editors/armature/pose_transform.c b/source/blender/editors/armature/pose_transform.c
index fa7850b..b645f1f 100644
--- a/source/blender/editors/armature/pose_transform.c
+++ b/source/blender/editors/armature/pose_transform.c
@@ -414,7 +414,6 @@ static bPoseChannel *pose_bone_do_paste(Object *ob, bPoseChannel *chan, const bo
 
 static int pose_copy_exec(bContext *C, wmOperator *op)
 {
-	Main *bmain = CTX_data_main(C);
 	Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
 	char str[FILE_MAX];
 	/* Sanity checking. */
@@ -424,13 +423,36 @@ static int pose_copy_exec(bContext *C, wmOperator *op)
 	}
 	/* Sets chan->flag to POSE_KEY if bone selected. */
 	set_pose_keys(ob);
+	/* Construct a local bmain and only put object and it's data into it,
+	 * o this way we don't expand any other objects into the copy buffer
+	 * file.
+	 *
+	 * TODO(sergey): Find an easier way to tell copy buffer to only store
+	 * data we are actually interested in. Maybe pass it a flag to skip
+	 * any datablock expansion?
+	 */
+	Main *temp_bmain = BKE_main_new();
+	Object ob_copy = *ob;
+	bArmature arm_copy = *((bArmature *)ob->data);
+	ob_copy.data = &arm_copy;
+	BLI_addtail(&temp_bmain->object, &ob_copy);
+	BLI_addtail(&temp_bmain->armature, &arm_copy);
+	/* begin copy buffer on a temp bmain. */
+	BKE_copybuffer_begin(temp_bmain);
 	/* Store the whole object to the copy buffer because pose can't be
 	 * existing on it's own.
 	 */
-	BKE_copybuffer_begin(bmain);
-	BKE_copybuffer_tag_ID(&ob->id);
+	BKE_copybuffer_tag_ID(&ob_copy.id);
 	BLI_make_file_string("/", str, BKE_tempdir_base(), "copybuffer_pose.blend");
-	BKE_copybuffer_save(bmain, str, op->reports);
+	BKE_copybuffer_save(temp_bmain, str, op->reports);
+	/* We clear the lists so no datablocks gets freed,
+	 * This is required because objects in temp bmain shares same pointers
+	 * as the real ones.
+	 */
+	BLI_listbase_clear(&temp_bmain->object);
+	BLI_listbase_clear(&temp_bmain->armature);
+	BKE_main_free(temp_bmain);
+	/* We are all done! */
 	BKE_report(op->reports, RPT_INFO, "Copied pose to buffer");
 	return OPERATOR_FINISHED;
 }




More information about the Bf-blender-cvs mailing list