[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25778] trunk/blender: fix for crash when setting a shapekeys name in rna, ( probably other properties too).

Campbell Barton ideasman42 at gmail.com
Wed Jan 6 13:19:46 CET 2010


Revision: 25778
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25778
Author:   campbellbarton
Date:     2010-01-06 13:19:46 +0100 (Wed, 06 Jan 2010)

Log Message:
-----------
fix for crash when setting a shapekeys name in rna, (probably other properties too).
When the shapekey was returned from the object it didnt use the data's ID which is expected elsewhere in RNA.

Transfer shape now also sets the name.

Modified Paths:
--------------
    trunk/blender/release/scripts/op/object.py
    trunk/blender/source/blender/makesrna/intern/rna_object.c
    trunk/blender/source/blender/makesrna/intern/rna_object_api.c

Modified: trunk/blender/release/scripts/op/object.py
===================================================================
--- trunk/blender/release/scripts/op/object.py	2010-01-06 12:05:46 UTC (rev 25777)
+++ trunk/blender/release/scripts/op/object.py	2010-01-06 12:19:46 UTC (rev 25778)
@@ -176,11 +176,12 @@
         def me_cos(verts):
             return [v.co.copy() for v in verts]
 
-        def ob_add_shape(ob):
+        def ob_add_shape(ob, name):
             me = ob.data
-            ob.add_shape_key(from_mix=False)
+            key = ob.add_shape_key(from_mix=False)
             if len(me.shape_keys.keys) == 1:
-                ob.add_shape_key(from_mix=False) # we need a rest
+                key = ob.add_shape_key(from_mix=False) # we need a rest
+            key.name = name
             ob.active_shape_key_index = len(me.shape_keys.keys) - 1
             ob.shape_key_lock = True
 
@@ -191,6 +192,7 @@
             use_clamp = False
 
         me = ob_act.data
+        orig_key_name = ob_act.active_shape_key.name
 
         orig_shape_coords = me_cos(ob_act.active_shape_key.data)
 
@@ -206,7 +208,7 @@
             target_normals = me_nos(me_other.verts)
             target_coords = me_cos(me_other.verts)
 
-            ob_add_shape(ob_other)
+            ob_add_shape(ob_other, orig_key_name)
 
             # editing the final coords, only list that stores wrapped coords
             target_shape_coords = [v.co for v in ob_other.active_shape_key.data]

Modified: trunk/blender/source/blender/makesrna/intern/rna_object.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_object.c	2010-01-06 12:05:46 UTC (rev 25777)
+++ trunk/blender/source/blender/makesrna/intern/rna_object.c	2010-01-06 12:19:46 UTC (rev 25778)
@@ -930,7 +930,7 @@
 		return PointerRNA_NULL;
 	
 	kb= BLI_findlink(&key->block, ob->shapenr-1);
-	RNA_pointer_create(&key->id, &RNA_ShapeKey, kb, &keyptr);
+	RNA_pointer_create((ID *)ob->data, &RNA_ShapeKey, kb, &keyptr);
 	return keyptr;
 }
 

Modified: trunk/blender/source/blender/makesrna/intern/rna_object_api.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_object_api.c	2010-01-06 12:05:46 UTC (rev 25777)
+++ trunk/blender/source/blender/makesrna/intern/rna_object_api.c	2010-01-06 12:19:46 UTC (rev 25778)
@@ -310,19 +310,23 @@
 	return ob_arm;
 }
 
-static KeyBlock *rna_Object_add_shape_key(Object *ob, bContext *C, ReportList *reports, char *name, int from_mix)
+static PointerRNA rna_Object_add_shape_key(Object *ob, bContext *C, ReportList *reports, char *name, int from_mix)
 {
 	Scene *scene= CTX_data_scene(C);
 	KeyBlock *kb= NULL;
 
 	if((kb=object_insert_shape_key(scene, ob, name, from_mix))) {
+		PointerRNA keyptr;
+
+		RNA_pointer_create((ID *)ob->data, &RNA_ShapeKey, kb, &keyptr);
 		WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
+		
+		return keyptr;
 	}
 	else {
 		BKE_reportf(reports, RPT_ERROR, "Object \"%s\"does not support shapes.", ob->id.name+2);
+		return PointerRNA_NULL;
 	}
-
-	return kb;
 }
 
 int rna_Object_is_visible(Object *ob, bContext *C)
@@ -476,6 +480,7 @@
 	parm= RNA_def_string(func, "name", "Key", 0, "", "Unique name for the new keylock."); /* optional */
 	parm= RNA_def_boolean(func, "from_mix", 1, "", "Create new shape from existing mix of shapes.");
 	parm= RNA_def_pointer(func, "key", "ShapeKey", "", "New shape keyblock.");
+	RNA_def_property_flag(parm, PROP_RNAPTR);
 	RNA_def_function_return(func, parm);
 
 	/* Ray Cast */





More information about the Bf-blender-cvs mailing list