[Bf-blender-cvs] [49fe27ee46b] master: Modifiers: sanitize/cleanup modifiers' copying & freeing code.

Bastien Montagne noreply at git.blender.org
Tue May 8 14:22:23 CEST 2018


Commit: 49fe27ee46b4d9272957c21c13365db322ca8396
Author: Bastien Montagne
Date:   Tue May 8 14:21:02 2018 +0200
Branches: master
https://developer.blender.org/rB49fe27ee46b4d9272957c21c13365db322ca8396

Modifiers: sanitize/cleanup modifiers' copying & freeing code.

Should also fix T55000: Crash with hooks and curves in Cycles render.

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

M	source/blender/modifiers/intern/MOD_collision.c
M	source/blender/modifiers/intern/MOD_explode.c
M	source/blender/modifiers/intern/MOD_fluidsim.c
M	source/blender/modifiers/intern/MOD_fluidsim_util.c
M	source/blender/modifiers/intern/MOD_hook.c
M	source/blender/modifiers/intern/MOD_ocean.c
M	source/blender/modifiers/intern/MOD_subsurf.c
M	source/blender/modifiers/intern/MOD_surface.c
M	source/blender/modifiers/intern/MOD_surfacedeform.c
M	source/blender/modifiers/intern/MOD_warp.c

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

diff --git a/source/blender/modifiers/intern/MOD_collision.c b/source/blender/modifiers/intern/MOD_collision.c
index 0a15799f61a..f2698b43652 100644
--- a/source/blender/modifiers/intern/MOD_collision.c
+++ b/source/blender/modifiers/intern/MOD_collision.c
@@ -69,7 +69,7 @@ static void freeData(ModifierData *md)
 {
 	CollisionModifierData *collmd = (CollisionModifierData *) md;
 	
-	if (collmd) {
+	if (collmd) {  /* Seriously? */
 		if (collmd->bvhtree) {
 			BLI_bvhtree_free(collmd->bvhtree);
 			collmd->bvhtree = NULL;
diff --git a/source/blender/modifiers/intern/MOD_explode.c b/source/blender/modifiers/intern/MOD_explode.c
index c22901f1947..600dc3e28d1 100644
--- a/source/blender/modifiers/intern/MOD_explode.c
+++ b/source/blender/modifiers/intern/MOD_explode.c
@@ -66,7 +66,7 @@ static void freeData(ModifierData *md)
 {
 	ExplodeModifierData *emd = (ExplodeModifierData *) md;
 	
-	if (emd->facepa) MEM_freeN(emd->facepa);
+	MEM_SAFE_FREE(emd->facepa);
 }
 static void copyData(ModifierData *md, ModifierData *target)
 {
diff --git a/source/blender/modifiers/intern/MOD_fluidsim.c b/source/blender/modifiers/intern/MOD_fluidsim.c
index 37eabdf2425..823e67a7bc9 100644
--- a/source/blender/modifiers/intern/MOD_fluidsim.c
+++ b/source/blender/modifiers/intern/MOD_fluidsim.c
@@ -70,14 +70,17 @@ static void copyData(ModifierData *md, ModifierData *target)
 	FluidsimModifierData *fluidmd = (FluidsimModifierData *) md;
 	FluidsimModifierData *tfluidmd = (FluidsimModifierData *) target;
 	
-	fluidsim_free(tfluidmd);
-
 	if (fluidmd->fss) {
 		tfluidmd->fss = MEM_dupallocN(fluidmd->fss);
 		if (tfluidmd->fss && (tfluidmd->fss->meshVelocities != NULL)) {
 			tfluidmd->fss->meshVelocities = MEM_dupallocN(tfluidmd->fss->meshVelocities);
 		}
 	}
+
+	/* Seems to never be used, but for sqke of consistency... */
+	BLI_assert(fluidmd->point_cache == NULL);
+	BLI_assert(tfluidmd->point_cache == NULL);
+	tfluidmd->point_cache = NULL;
 }
 
 
diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c
index 72c44121e0b..07d0b48fdb4 100644
--- a/source/blender/modifiers/intern/MOD_fluidsim_util.c
+++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c
@@ -155,6 +155,10 @@ void fluidsim_free(FluidsimModifierData *fluidmd)
 		}
 		MEM_SAFE_FREE(fluidmd->fss);
 	}
+
+	/* Seems to never be used, but for sqke of consistency... */
+	BLI_assert(fluidmd->point_cache == NULL);
+	fluidmd->point_cache = NULL;
 	
 	return;
 }
diff --git a/source/blender/modifiers/intern/MOD_hook.c b/source/blender/modifiers/intern/MOD_hook.c
index 80c029157f7..80f07f579cd 100644
--- a/source/blender/modifiers/intern/MOD_hook.c
+++ b/source/blender/modifiers/intern/MOD_hook.c
@@ -67,13 +67,6 @@ static void copyData(ModifierData *md, ModifierData *target)
 	HookModifierData *hmd = (HookModifierData *) md;
 	HookModifierData *thmd = (HookModifierData *) target;
 
-	if (thmd->curfalloff != NULL) {
-		curvemapping_free(thmd->curfalloff);
-	}
-	if (thmd->indexar != NULL) {
-		MEM_freeN(thmd->indexar);
-	}
-
 	modifier_copyData_generic(md, target);
 
 	thmd->curfalloff = curvemapping_copy(hmd->curfalloff);
@@ -99,7 +92,7 @@ static void freeData(ModifierData *md)
 
 	curvemapping_free(hmd->curfalloff);
 
-	if (hmd->indexar) MEM_freeN(hmd->indexar);
+	MEM_SAFE_FREE(hmd->indexar);
 }
 
 static bool isDisabled(ModifierData *md, int UNUSED(useRenderParams))
diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c
index a9c4afcc0af..240b6247cf5 100644
--- a/source/blender/modifiers/intern/MOD_ocean.c
+++ b/source/blender/modifiers/intern/MOD_ocean.c
@@ -167,8 +167,6 @@ static void copyData(ModifierData *md, ModifierData *target)
 #endif
 	OceanModifierData *tomd = (OceanModifierData *) target;
 
-	freeData(target);
-
 	modifier_copyData_generic(md, target);
 
 	tomd->refresh = 0;
diff --git a/source/blender/modifiers/intern/MOD_subsurf.c b/source/blender/modifiers/intern/MOD_subsurf.c
index 8711384e1ee..288c684269e 100644
--- a/source/blender/modifiers/intern/MOD_subsurf.c
+++ b/source/blender/modifiers/intern/MOD_subsurf.c
@@ -82,9 +82,11 @@ static void freeData(ModifierData *md)
 
 	if (smd->mCache) {
 		ccgSubSurf_free(smd->mCache);
+		smd->mCache = NULL;
 	}
 	if (smd->emCache) {
 		ccgSubSurf_free(smd->emCache);
+		smd->emCache = NULL;
 	}
 }
 
diff --git a/source/blender/modifiers/intern/MOD_surface.c b/source/blender/modifiers/intern/MOD_surface.c
index bed8f95fb87..353cea80d3f 100644
--- a/source/blender/modifiers/intern/MOD_surface.c
+++ b/source/blender/modifiers/intern/MOD_surface.c
@@ -63,20 +63,17 @@ static void freeData(ModifierData *md)
 	if (surmd) {
 		if (surmd->bvhtree) {
 			free_bvhtree_from_mesh(surmd->bvhtree);
-			MEM_freeN(surmd->bvhtree);
+			MEM_SAFE_FREE(surmd->bvhtree);
 		}
 
-		if (surmd->dm)
+		if (surmd->dm) {
 			surmd->dm->release(surmd->dm);
+			surmd->dm = NULL;
+		}
 
-		if (surmd->x)
-			MEM_freeN(surmd->x);
+		MEM_SAFE_FREE(surmd->x);
 		
-		if (surmd->v)
-			MEM_freeN(surmd->v);
-
-		surmd->bvhtree = NULL;
-		surmd->dm = NULL;
+		MEM_SAFE_FREE(surmd->v);
 	}
 }
 
diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.c b/source/blender/modifiers/intern/MOD_surfacedeform.c
index e0c94d456c2..9abb9e3fe72 100644
--- a/source/blender/modifiers/intern/MOD_surfacedeform.c
+++ b/source/blender/modifiers/intern/MOD_surfacedeform.c
@@ -124,12 +124,11 @@ static void freeData(ModifierData *md)
 					MEM_SAFE_FREE(smd->verts[i].binds[j].vert_weights);
 				}
 
-				MEM_freeN(smd->verts[i].binds);
+				MEM_SAFE_FREE(smd->verts[i].binds);
 			}
 		}
 
-		MEM_freeN(smd->verts);
-		smd->verts = NULL;
+		MEM_SAFE_FREE(smd->verts);
 	}
 }
 
@@ -138,8 +137,6 @@ static void copyData(ModifierData *md, ModifierData *target)
 	SurfaceDeformModifierData *smd = (SurfaceDeformModifierData *)md;
 	SurfaceDeformModifierData *tsmd = (SurfaceDeformModifierData *)target;
 
-	freeData(target);
-
 	modifier_copyData_generic(md, target);
 
 	if (smd->verts) {
diff --git a/source/blender/modifiers/intern/MOD_warp.c b/source/blender/modifiers/intern/MOD_warp.c
index 00d7906a442..a22120d7b3d 100644
--- a/source/blender/modifiers/intern/MOD_warp.c
+++ b/source/blender/modifiers/intern/MOD_warp.c
@@ -66,10 +66,6 @@ static void copyData(ModifierData *md, ModifierData *target)
 	WarpModifierData *wmd = (WarpModifierData *) md;
 	WarpModifierData *twmd = (WarpModifierData *) target;
 
-	if (twmd->curfalloff != NULL) {
-		curvemapping_free(twmd->curfalloff);
-	}
-
 	modifier_copyData_generic(md, target);
 
 	twmd->curfalloff = curvemapping_copy(wmd->curfalloff);



More information about the Bf-blender-cvs mailing list