[Bf-blender-cvs] [6afb7546d38] hair_guides_grooming: Set the numshapeverts of bundles as soon as possible to avoid invalid array access.

Lukas Tönne noreply at git.blender.org
Sun Jun 3 12:15:44 CEST 2018


Commit: 6afb7546d380eb1b62271e717c7dc7da70ef21c6
Author: Lukas Tönne
Date:   Sun Jun 3 11:15:17 2018 +0100
Branches: hair_guides_grooming
https://developer.blender.org/rB6afb7546d380eb1b62271e717c7dc7da70ef21c6

Set the numshapeverts of bundles as soon as possible to avoid invalid array access.

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

M	source/blender/blenkernel/intern/groom.c

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

diff --git a/source/blender/blenkernel/intern/groom.c b/source/blender/blenkernel/intern/groom.c
index 722bca4d993..90bea0aa99f 100644
--- a/source/blender/blenkernel/intern/groom.c
+++ b/source/blender/blenkernel/intern/groom.c
@@ -326,10 +326,11 @@ static bool groom_get_bundle_transform_on_scalp(const GroomBundle *bundle, const
 	}
 }
 
-static bool groom_shape_rebuild(GroomBundle *bundle, int numshapeverts, Object *scalp_ob)
+static bool groom_shape_rebuild(GroomBundle *bundle, Object *scalp_ob)
 {
 	BLI_assert(bundle->scalp_region != NULL);
 	BLI_assert(scalp_ob->type == OB_MESH);
+	const int numshapeverts = bundle->numshapeverts;
 	
 	bool result = true;
 	float (*shape)[2] = MEM_mallocN(sizeof(*shape) * numshapeverts, "groom section shape");
@@ -364,7 +365,6 @@ static bool groom_shape_rebuild(GroomBundle *bundle, int numshapeverts, Object *
 		shape[i][1] = dot_v3v3(co, center_mat[1]);
 	}
 	
-	bundle->numshapeverts = numshapeverts;
 	bundle->totverts = numshapeverts * bundle->totsections;
 	bundle->verts = MEM_reallocN_id(bundle->verts, sizeof(*bundle->verts) * bundle->totverts, "groom bundle vertices");
 	/* Set the shape for all sections */
@@ -438,7 +438,7 @@ static bool groom_bundle_region_from_mesh_fmap(GroomBundle *bundle, Object *scal
 		goto finalize;
 	}
 	
-	const int numshapeverts = BMO_slot_buffer_count(op.slots_out, "boundary");
+	const int numshapeverts = bundle->numshapeverts = BMO_slot_buffer_count(op.slots_out, "boundary");
 	bundle->scalp_region = MEM_callocN(sizeof(*bundle->scalp_region) * (numshapeverts + 1), "groom bundle scalp region");
 	
 	float center_co[3]; /* average vertex location for placing the center */
@@ -494,7 +494,7 @@ static bool groom_bundle_region_from_mesh_fmap(GroomBundle *bundle, Object *scal
 finalize:
 	if (result == true)
 	{
-		groom_shape_rebuild(bundle, numshapeverts, scalp_ob);
+		groom_shape_rebuild(bundle, scalp_ob);
 	}
 	else
 	{



More information about the Bf-blender-cvs mailing list