[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43600] trunk/blender/source/blender/ modifiers/intern: Fix a crasher in WeightVG modifiers.

Bastien Montagne montagne29 at wanadoo.fr
Sun Jan 22 11:14:14 CET 2012


Revision: 43600
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43600
Author:   mont29
Date:     2012-01-22 10:14:01 +0000 (Sun, 22 Jan 2012)
Log Message:
-----------
Fix a crasher in WeightVG modifiers.

Problem was, if no vertices were ever added to one of the obect's vgroups, there is no CD_DEFORMVERT layer, even though there might be several valid vgroup indices... Odd no one noticed that earlier.

Many thanks to miikah for finding that bug!

Modified Paths:
--------------
    trunk/blender/source/blender/modifiers/intern/MOD_weightvgedit.c
    trunk/blender/source/blender/modifiers/intern/MOD_weightvgmix.c
    trunk/blender/source/blender/modifiers/intern/MOD_weightvgproximity.c

Modified: trunk/blender/source/blender/modifiers/intern/MOD_weightvgedit.c
===================================================================
--- trunk/blender/source/blender/modifiers/intern/MOD_weightvgedit.c	2012-01-22 06:10:21 UTC (rev 43599)
+++ trunk/blender/source/blender/modifiers/intern/MOD_weightvgedit.c	2012-01-22 10:14:01 UTC (rev 43600)
@@ -204,6 +204,17 @@
 		return dm;
 
 	dvert = CustomData_duplicate_referenced_layer(&dm->vertData, CD_MDEFORMVERT, numVerts);
+	/* If no vertices were ever added to an object's vgroup, dvert might be NULL. */
+	if(!dvert)
+		/* If this modifier is not allowed to add vertices, just return. */
+		if(!do_add)
+			return dm;
+		/* Else, add a valid data layer! */
+		dvert = CustomData_add_layer_named(&dm->vertData, CD_MDEFORMVERT, CD_CALLOC,
+		                                   NULL, numVerts, wmd->defgrp_name);
+		/* Ultimate security check. */
+		if(!dvert)
+			return dm;
 
 	/* Get org weights, assuming 0.0 for vertices not in given vgroup. */
 	org_w = MEM_mallocN(sizeof(float) * numVerts, "WeightVGEdit Modifier, org_w");

Modified: trunk/blender/source/blender/modifiers/intern/MOD_weightvgmix.c
===================================================================
--- trunk/blender/source/blender/modifiers/intern/MOD_weightvgmix.c	2012-01-22 06:10:21 UTC (rev 43599)
+++ trunk/blender/source/blender/modifiers/intern/MOD_weightvgmix.c	2012-01-22 10:14:01 UTC (rev 43600)
@@ -251,6 +251,17 @@
 	}
 
 	dvert = CustomData_duplicate_referenced_layer(&dm->vertData, CD_MDEFORMVERT, numVerts);
+	/* If no vertices were ever added to an object's vgroup, dvert might be NULL. */
+	if(!dvert)
+		/* If not affecting all vertices, just return. */
+		if(wmd->mix_set != MOD_WVG_SET_ALL)
+			return dm;
+		/* Else, add a valid data layer! */
+		dvert = CustomData_add_layer_named(&dm->vertData, CD_MDEFORMVERT, CD_CALLOC,
+		                                   NULL, numVerts, wmd->defgrp_name_a);
+		/* Ultimate security check. */
+		if(!dvert)
+			return dm;
 
 	/* Find out which vertices to work on. */
 	tidx = MEM_mallocN(sizeof(int) * numVerts, "WeightVGMix Modifier, tidx");

Modified: trunk/blender/source/blender/modifiers/intern/MOD_weightvgproximity.c
===================================================================
--- trunk/blender/source/blender/modifiers/intern/MOD_weightvgproximity.c	2012-01-22 06:10:21 UTC (rev 43599)
+++ trunk/blender/source/blender/modifiers/intern/MOD_weightvgproximity.c	2012-01-22 10:14:01 UTC (rev 43600)
@@ -378,6 +378,10 @@
 		return dm;
 
 	dvert = CustomData_duplicate_referenced_layer(&dm->vertData, CD_MDEFORMVERT, numVerts);
+	/* If no vertices were ever added to an object's vgroup, dvert might be NULL.
+	 * As this modifier never add vertices to vgroup, just return. */
+	if(!dvert)
+		return dm;
 
 	/* Find out which vertices to work on (all vertices in vgroup), and get their relevant weight.
 	 */



More information about the Bf-blender-cvs mailing list