[Bf-blender-cvs] [013a5c8b774] blender2.8: MOD_wave: fix various issues.

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


Commit: 013a5c8b7742626b6c4223e7e4235ec6ecb5ab39
Author: Bastien Montagne
Date:   Tue Nov 27 20:36:54 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB013a5c8b7742626b6c4223e7e4235ec6ecb5ab39

MOD_wave: fix various issues.

Missing dependsOnNormal callback, potential usage of NULL mesh
pointer, style...

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

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

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

diff --git a/source/blender/modifiers/intern/MOD_wave.c b/source/blender/modifiers/intern/MOD_wave.c
index 0849b268f7f..553f552bb0a 100644
--- a/source/blender/modifiers/intern/MOD_wave.c
+++ b/source/blender/modifiers/intern/MOD_wave.c
@@ -142,6 +142,13 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
 	return dataMask;
 }
 
+static bool dependsOnNormals(ModifierData *md)
+{
+	WaveModifierData *wmd = (WaveModifierData *)md;
+
+	return (wmd->flag & MOD_WAVE_NORM) != 0;
+}
+
 static void waveModifier_do(
         WaveModifierData *md,
         Depsgraph *depsgraph,
@@ -160,8 +167,9 @@ static void waveModifier_do(
 	const float falloff = wmd->falloff;
 	float falloff_fac = 1.0f; /* when falloff == 0.0f this stays at 1.0f */
 
-	if ((wmd->flag & MOD_WAVE_NORM) && (ob->type == OB_MESH))
+	if ((wmd->flag & MOD_WAVE_NORM) && (mesh != NULL)) {
 		mvert = mesh->mvert;
+	}
 
 	if (wmd->objectcenter) {
 		float mat[4][4];
@@ -176,7 +184,9 @@ static void waveModifier_do(
 	/* get the index of the deform group */
 	MOD_get_vgroup(ob, mesh, wmd->defgrp_name, &dvert, &defgrp_index);
 
-	if (wmd->damp == 0) wmd->damp = 10.0f;
+	if (wmd->damp == 0.0f) {
+		wmd->damp = 10.0f;
+	}
 
 	if (wmd->lifetime != 0.0f) {
 		float x = ctime - wmd->timeoffs;
@@ -189,9 +199,8 @@ static void waveModifier_do(
 		}
 	}
 
-	if (wmd->texture) {
-		tex_co = MEM_malloc_arrayN(numVerts, sizeof(*tex_co),
-		                     "waveModifier_do tex_co");
+	if (mesh != NULL && wmd->texture) {
+		tex_co = MEM_malloc_arrayN(numVerts, sizeof(*tex_co), "waveModifier_do tex_co");
 		MOD_get_texture_coords((MappingInfoModifierData *)wmd, ob, mesh, vertexCos, tex_co);
 
 		MOD_init_texture(depsgraph, wmd->texture);
@@ -199,7 +208,7 @@ static void waveModifier_do(
 
 	if (lifefac != 0.0f) {
 		/* avoid divide by zero checks within the loop */
-		float falloff_inv = falloff ? 1.0f / falloff : 1.0f;
+		float falloff_inv = falloff != 0.0f ? 1.0f / falloff : 1.0f;
 		int i;
 
 		for (i = 0; i < numVerts; i++) {
@@ -295,7 +304,7 @@ static void waveModifier_do(
 		}
 	}
 
-	if (wmd->texture) MEM_freeN(tex_co);
+	MEM_SAFE_FREE(tex_co);
 }
 
 static void deformVerts(
@@ -304,13 +313,15 @@ static void deformVerts(
         float (*vertexCos)[3],
         int numVerts)
 {
-	Mesh *mesh_src = mesh;
 	WaveModifierData *wmd = (WaveModifierData *)md;
+	Mesh *mesh_src = NULL;
 
-	if (wmd->flag & MOD_WAVE_NORM)
+	if (wmd->flag & MOD_WAVE_NORM) {
 		mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, vertexCos, numVerts, true, false);
-	else if (wmd->texture || wmd->defgrp_name[0])
+	}
+	else if (wmd->texture != NULL || wmd->defgrp_name[0] != '\0') {
 		mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, numVerts, false, false);
+	}
 
 	waveModifier_do(wmd, ctx->depsgraph, ctx->object, mesh_src, vertexCos, numVerts);
 
@@ -324,13 +335,15 @@ static void deformVertsEM(
         struct BMEditMesh *editData,
         Mesh *mesh, float (*vertexCos)[3], int numVerts)
 {
-	Mesh *mesh_src = mesh;
 	WaveModifierData *wmd = (WaveModifierData *)md;
+	Mesh *mesh_src = NULL;
 
-	if (wmd->flag & MOD_WAVE_NORM)
+	if (wmd->flag & MOD_WAVE_NORM) {
 		mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, vertexCos, numVerts, true, false);
-	else if (wmd->texture || wmd->defgrp_name[0])
+	}
+	else if (wmd->texture != NULL || wmd->defgrp_name[0] != '\0') {
 		mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, NULL, numVerts, false, false);
+	}
 
 	waveModifier_do(wmd, ctx->depsgraph, ctx->object, mesh_src, vertexCos, numVerts);
 
@@ -369,7 +382,7 @@ ModifierTypeInfo modifierType_Wave = {
 	/* isDisabled */        NULL,
 	/* updateDepsgraph */   updateDepsgraph,
 	/* dependsOnTime */     dependsOnTime,
-	/* dependsOnNormals */	NULL,
+	/* dependsOnNormals */	dependsOnNormals,
 	/* foreachObjectLink */ foreachObjectLink,
 	/* foreachIDLink */     foreachIDLink,
 	/* foreachTexLink */    foreachTexLink,



More information about the Bf-blender-cvs mailing list