[Bf-blender-cvs] [9c82cc5123f] blender2.8: MOD_smooth: do not compute mesh when not needed.

Bastien Montagne noreply at git.blender.org
Tue Nov 27 21:17:26 CET 2018


Commit: 9c82cc5123fb841f4ae87ddc0ceb61538c70da0f
Author: Bastien Montagne
Date:   Tue Nov 27 14:26:43 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB9c82cc5123fb841f4ae87ddc0ceb61538c70da0f

MOD_smooth: do not compute mesh when not needed.

Also fixes potential memory leak.

Related to T57972.

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

M	source/blender/modifiers/intern/MOD_smooth.c

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

diff --git a/source/blender/modifiers/intern/MOD_smooth.c b/source/blender/modifiers/intern/MOD_smooth.c
index 100d49f1c89..f7efd2dbd1b 100644
--- a/source/blender/modifiers/intern/MOD_smooth.c
+++ b/source/blender/modifiers/intern/MOD_smooth.c
@@ -109,7 +109,7 @@ static void smoothModifier_do(
 	fac = smd->fac;
 	facm = 1 - fac;
 
-	if (mesh->totvert == numVerts) {
+	if (mesh != NULL) {
 		medges = mesh->medge;
 		numDMEdges = mesh->totedge;
 	}
@@ -213,22 +213,27 @@ static void deformVerts(
         ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh,
         float (*vertexCos)[3], int numVerts)
 {
-	Mesh *mesh_src = mesh;
+	SmoothModifierData *smd = (SmoothModifierData *)md;
+	Mesh *mesh_src = NULL;
 
-	if (mesh_src == NULL) {
-		mesh_src = ctx->object->data;
+	if (ctx->object->type == OB_MESH) {
+		/* mesh_src is needed for vgroups, and taking edges into account. */
+		mesh_src = MOD_get_mesh_eval(ctx->object, NULL, mesh, NULL, false, false);
+		BLI_assert(mesh_src->totvert == numVerts);
 	}
 
-	BLI_assert(mesh_src->totvert == numVerts);
+	smoothModifier_do(smd, ctx->object, mesh_src, vertexCos, numVerts);
 
-	smoothModifier_do((SmoothModifierData *)md, ctx->object, mesh_src,
-	                  vertexCos, numVerts);
+	if (!ELEM(mesh_src, NULL, mesh)) {
+		BKE_id_free(NULL, mesh_src);
+	}
 }
 
 static void deformVertsEM(
         ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *editData,
         Mesh *mesh, float (*vertexCos)[3], int numVerts)
 {
+	SmoothModifierData *smd = (SmoothModifierData *)md;
 	Mesh *mesh_src = mesh;
 
 	if (mesh_src == NULL) {
@@ -237,10 +242,9 @@ static void deformVertsEM(
 
 	BLI_assert(mesh_src->totvert == numVerts);
 
-	smoothModifier_do((SmoothModifierData *)md, ctx->object, mesh_src,
-	                  vertexCos, numVerts);
+	smoothModifier_do(smd, ctx->object, mesh_src, vertexCos, numVerts);
 
-	if (!mesh) {
+	if (!ELEM(mesh_src, NULL, mesh)) {
 		BKE_id_free(NULL, mesh_src);
 	}
 }



More information about the Bf-blender-cvs mailing list