[Bf-blender-cvs] [ef88b4f98bb] sculpt-dev: Sculpt: fix crash in multires layer brush

Joseph Eagar noreply at git.blender.org
Mon Sep 27 00:51:02 CEST 2021


Commit: ef88b4f98bb08a60a2b7a1d38dbb661b94560a71
Author: Joseph Eagar
Date:   Sun Sep 26 15:50:24 2021 -0700
Branches: sculpt-dev
https://developer.blender.org/rBef88b4f98bb08a60a2b7a1d38dbb661b94560a71

Sculpt: fix crash in multires layer brush

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

M	source/blender/blenkernel/intern/paint.c
M	source/blender/editors/sculpt_paint/sculpt.c

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

diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index f7e995b883c..fb5db35b339 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -1520,8 +1520,10 @@ void BKE_sculptsession_free(Object *ob)
 
     if (ss->layers_to_free) {
       for (int i = 0; i < ss->tot_layers_to_free; i++) {
-        SCULPT_temp_customlayer_release(ss, ss->layers_to_free[i]);
-        MEM_freeN(ss->layers_to_free[i]);
+        if (ss->layers_to_free[i]) {
+          SCULPT_temp_customlayer_release(ss, ss->layers_to_free[i]);
+          // SCULPT_temp_customlayer_release frees layers_to_free[i] itself
+        }
       }
 
       MEM_freeN(ss->layers_to_free);
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index f3e98c6d405..937b65a83e5 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -525,7 +525,7 @@ ATTR_NO_OPT static bool sculpt_temp_customlayer_get(SculptSession *ss,
         switch (domain) {
           case ATTR_DOMAIN_POINT:
             cdata = ss->vdata;
-            totelem = ss->totvert;
+            totelem = SCULPT_vertex_count_get(ss);
             break;
           case ATTR_DOMAIN_FACE:
             cdata = ss->pdata;
@@ -553,11 +553,6 @@ ATTR_NO_OPT static bool sculpt_temp_customlayer_get(SculptSession *ss,
       }
     }
 
-    if (!cdata) {
-      printf("error in %s\n", __func__);
-      return false;
-    }
-
     CustomData dummy = {0};
     CustomData_reset(&dummy);
     CustomData_add_layer(&dummy, proptype, CD_ASSIGN, NULL, 0);
@@ -573,6 +568,7 @@ ATTR_NO_OPT static bool sculpt_temp_customlayer_get(SculptSession *ss,
     out->layer = NULL;
     out->domain = domain;
     out->proptype = proptype;
+    out->elemsize = elemsize;
 
     /*grids cannot store normal customdata layers, and thus
       we cannot rely on the customdata api to keep track of
@@ -748,7 +744,7 @@ ATTR_NO_OPT void SCULPT_update_customdata_refs(SculptSession *ss)
     for (int j = 0; j < SCULPT_SCL_LAYER_MAX; j++) {
       SculptCustomLayer *scl = ss->custom_layers[j];
 
-      if (scl && !scl->released) {
+      if (scl && !scl->released && !scl->params.simple_array) {
         sculpt_temp_customlayer_get(
             ss, scl->domain, scl->proptype, scl->name, scl, true, &scl->params);
       }
@@ -798,6 +794,14 @@ bool SCULPT_temp_customlayer_release(SculptSession *ss, SculptCustomLayer *scl)
     return false;
   }
 
+  // remove from layers_to_free list if necassary
+  for (int i = 0; scl->data && i < ss->tot_layers_to_free; i++) {
+    if (ss->layers_to_free[i] && ss->layers_to_free[i]->data == scl->data) {
+      MEM_freeN(ss->layers_to_free[i]);
+      ss->layers_to_free[i] = NULL;
+    }
+  }
+
   scl->released = true;
 
   if (!scl->from_bmesh) {



More information about the Bf-blender-cvs mailing list