Modifiers: sanitize/cleanup modifiers' copying & freeing code.
authorBastien Montagne <montagne29@wanadoo.fr>
Tue, 8 May 2018 12:21:02 +0000 (14:21 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Tue, 8 May 2018 12:22:14 +0000 (14:22 +0200)
Should also fix T55000: Crash with hooks and curves in Cycles render.

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

index 0a15799f61a12dfa5d0e51519952b010491f2367..f2698b43652830d16125f3f7bcc2347b6654e43e 100644 (file)
@@ -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;
index c22901f19478b2ae9ee2769066302894d1161374..600dc3e28d10ba2365ffb4e594a8445885ebc4de 100644 (file)
@@ -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)
 {
index 37eabdf24256a29c10d01a5666a42041a0aef69a..823e67a7bc904256391e6010f2c54143ef0ce66d 100644 (file)
@@ -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;
 }
 
 
index 72c44121e0b615eeb79df237ef8349472acbe473..07d0b48fdb44a8880aa21082d502fb897f775e12 100644 (file)
@@ -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;
 }
index 80c029157f70e99ced1be1f24e60df8690459f32..80f07f579cd39220ebda17ce460b2b86cf29b298 100644 (file)
@@ -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))
index a9c4afcc0af18f82bf8ef4f731731b40bf241317..240b6247cf5f1a5eab21227c956b9e541282a20c 100644 (file)
@@ -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;
index 8711384e1eee17a4d31964329f48a8920502968e..288c684269e39d99d7659a7ea7826bc34419b82f 100644 (file)
@@ -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;
        }
 }
 
index bed8f95fb87b834ad29dc3a943ab96084614252c..353cea80d3f9b4bfb048e0561be72bf71c6ae200 100644 (file)
@@ -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);
        }
 }
 
index e0c94d456c2575c5c20de48baf41f7d44fa291ce..9abb9e3fe722ee8385b5bcf6e27ff6ba56cbd9f4 100644 (file)
@@ -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) {
index 00d7906a442dbf766e7f36b92dabff878b126c01..a22120d7b3dbf707e2c0485c6199425a1df9979d 100644 (file)
@@ -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);