[Bf-blender-cvs] [958e6b1] alembic: Some NULL pointer checks in shape key code to ensure the Key struct can be used without a 'from' pointer.

Lukas Tönne noreply at git.blender.org
Sun May 3 18:29:58 CEST 2015


Commit: 958e6b1f20436b7f6b9f3cef3928feef170789ec
Author: Lukas Tönne
Date:   Sun May 3 12:44:49 2015 +0200
Branches: alembic
https://developer.blender.org/rB958e6b1f20436b7f6b9f3cef3928feef170789ec

Some NULL pointer checks in shape key code to ensure the Key struct can
be used without a 'from' pointer.

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

M	source/blender/blenkernel/intern/key.c
M	source/blender/editors/object/object_shapekey.c
M	source/blender/makesrna/intern/rna_key.c

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

diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index 3aea343..3d8950b 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -109,38 +109,40 @@ Key *BKE_key_add(ID *id)    /* common function */
 
 	key->uidgen = 1;
 	
-	/* XXX the code here uses some defines which will soon be deprecated... */
-	switch (GS(id->name)) {
-		case ID_ME:
-			el = key->elemstr;
-
-			el[0] = 3;
-			el[1] = IPO_FLOAT;
-			el[2] = 0;
-
-			key->elemsize = 12;
-
-			break;
-		case ID_LT:
-			el = key->elemstr;
-
-			el[0] = 3;
-			el[1] = IPO_FLOAT;
-			el[2] = 0;
-
-			key->elemsize = 12;
-
-			break;
-		case ID_CU:
-			el = key->elemstr;
-
-			el[0] = 4;
-			el[1] = IPO_BPOINT;
-			el[2] = 0;
-
-			key->elemsize = 16;
-
-			break;
+	if (id) {
+		/* XXX the code here uses some defines which will soon be deprecated... */
+		switch (GS(id->name)) {
+			case ID_ME:
+				el = key->elemstr;
+				
+				el[0] = 3;
+				el[1] = IPO_FLOAT;
+				el[2] = 0;
+				
+				key->elemsize = 12;
+				
+				break;
+			case ID_LT:
+				el = key->elemstr;
+				
+				el[0] = 3;
+				el[1] = IPO_FLOAT;
+				el[2] = 0;
+				
+				key->elemsize = 12;
+				
+				break;
+			case ID_CU:
+				el = key->elemstr;
+				
+				el[0] = 4;
+				el[1] = IPO_BPOINT;
+				el[2] = 0;
+				
+				key->elemsize = 16;
+				
+				break;
+		}
 	}
 	
 	return key;
@@ -514,7 +516,7 @@ static char *key_block_get_data(Key *key, KeyBlock *actkb, KeyBlock *kb, char **
 	if (kb == actkb) {
 		/* this hack makes it possible to edit shape keys in
 		 * edit mode with shape keys blending applied */
-		if (GS(key->from->name) == ID_ME) {
+		if (key->from && GS(key->from->name) == ID_ME) {
 			Mesh *me;
 			BMVert *eve;
 			BMIter iter;
diff --git a/source/blender/editors/object/object_shapekey.c b/source/blender/editors/object/object_shapekey.c
index 674eb25..9a8c8b3 100644
--- a/source/blender/editors/object/object_shapekey.c
+++ b/source/blender/editors/object/object_shapekey.c
@@ -97,10 +97,12 @@ static bool ED_object_shape_key_remove_all(Main *bmain, Object *ob)
 	if (key == NULL)
 		return false;
 
-	switch (GS(key->from->name)) {
-		case ID_ME: ((Mesh *)key->from)->key    = NULL; break;
-		case ID_CU: ((Curve *)key->from)->key   = NULL; break;
-		case ID_LT: ((Lattice *)key->from)->key = NULL; break;
+	if (key->from) {
+		switch (GS(key->from->name)) {
+			case ID_ME: ((Mesh *)key->from)->key    = NULL; break;
+			case ID_CU: ((Curve *)key->from)->key   = NULL; break;
+			case ID_LT: ((Lattice *)key->from)->key = NULL; break;
+		}
 	}
 
 	BKE_libblock_free_us(bmain, key);
@@ -162,10 +164,12 @@ static bool ED_object_shape_key_remove(Main *bmain, Object *ob)
 	}
 	
 	if (key->totkey == 0) {
-		switch (GS(key->from->name)) {
-			case ID_ME: ((Mesh *)key->from)->key    = NULL; break;
-			case ID_CU: ((Curve *)key->from)->key   = NULL; break;
-			case ID_LT: ((Lattice *)key->from)->key = NULL; break;
+		if (key->from) {
+			switch (GS(key->from->name)) {
+				case ID_ME: ((Mesh *)key->from)->key    = NULL; break;
+				case ID_CU: ((Curve *)key->from)->key   = NULL; break;
+				case ID_LT: ((Lattice *)key->from)->key = NULL; break;
+			}
 		}
 
 		BKE_libblock_free_us(bmain, key);
diff --git a/source/blender/makesrna/intern/rna_key.c b/source/blender/makesrna/intern/rna_key.c
index 249d132..d34af9f 100644
--- a/source/blender/makesrna/intern/rna_key.c
+++ b/source/blender/makesrna/intern/rna_key.c
@@ -303,7 +303,7 @@ static void rna_ShapeKey_data_begin(CollectionPropertyIterator *iter, PointerRNA
 	Nurb *nu;
 	int tot = kb->totelem, size = key->elemsize;
 	
-	if (GS(key->from->name) == ID_CU) {
+	if (key->from && GS(key->from->name) == ID_CU) {
 		cu = (Curve *)key->from;
 		nu = cu->nurb.first;
 		
@@ -324,7 +324,7 @@ static int rna_ShapeKey_data_length(PointerRNA *ptr)
 	Nurb *nu;
 	int tot = kb->totelem;
 	
-	if (GS(key->from->name) == ID_CU) {
+	if (key->from && GS(key->from->name) == ID_CU) {
 		cu = (Curve *)key->from;
 		nu = cu->nurb.first;
 		
@@ -342,7 +342,7 @@ static PointerRNA rna_ShapeKey_data_get(CollectionPropertyIterator *iter)
 	Curve *cu;
 	Nurb *nu;
 	
-	if (GS(key->from->name) == ID_CU) {
+	if (key->from && GS(key->from->name) == ID_CU) {
 		cu = (Curve *)key->from;
 		nu = cu->nurb.first;




More information about the Bf-blender-cvs mailing list