Fix T65693: Crash removing higher on special multires objects
[blender.git] / source / blender / blenkernel / intern / multires.c
index 7fefabd1c12bf4eb3b6ffb32be8d719173af1cc2..17d6b623b33e57feb24f641dc09622dd5c9f9e37 100644 (file)
@@ -634,20 +634,20 @@ static void multires_del_higher(MultiresModifierData *mmd, Object *ob, int lvl)
 
           disps = MEM_calloc_arrayN(totdisp, 3 * sizeof(float), "multires disps");
 
-          ndisps = disps;
-          hdisps = mdisp->disps;
-
-          multires_copy_grid(ndisps, hdisps, nsize, hsize);
-          if (mdisp->hidden) {
-            BLI_bitmap *gh = multires_mdisps_downsample_hidden(mdisp->hidden, mdisp->level, lvl);
-            MEM_freeN(mdisp->hidden);
-            mdisp->hidden = gh;
-          }
+          if (mdisp->disps != NULL) {
+            ndisps = disps;
+            hdisps = mdisp->disps;
+
+            multires_copy_grid(ndisps, hdisps, nsize, hsize);
+            if (mdisp->hidden) {
+              BLI_bitmap *gh = multires_mdisps_downsample_hidden(mdisp->hidden, mdisp->level, lvl);
+              MEM_freeN(mdisp->hidden);
+              mdisp->hidden = gh;
+            }
 
-          ndisps += nsize * nsize;
-          hdisps += hsize * hsize;
+            MEM_freeN(mdisp->disps);
+          }
 
-          MEM_freeN(mdisp->disps);
           mdisp->disps = disps;
           mdisp->totdisp = totdisp;
           mdisp->level = lvl;