Commit: 601d896fc66c21d94d2e54234e4325ab5cdf76b1
Author: Pablo Dobarro
Date:   Tue Jan 5 18:12:32 2021 +0100
Branches: sculpt-dev
https://developer.blender.org/rB601d896fc66c21d94d2e54234e4325ab5cdf76b1

Fix crash with custom input curves versioning

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

M       source/blender/blenkernel/intern/brush.c
M       source/blender/blenloader/intern/versioning_290.c
M       source/blender/editors/sculpt_paint/sculpt.c

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

diff --git a/source/blender/blenkernel/intern/brush.c 
b/source/blender/blenkernel/intern/brush.c
index 32713863299..21de0f7b72f 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -270,14 +270,16 @@ static void brush_reset_input_curve(CurveMapping *cumap)
 
 void BKE_brush_default_input_curves_set(Brush *brush)
 {
-  if (!brush->pressure_size_curve) {
-    brush->pressure_size_curve = BKE_curvemapping_add(1, 0, 0, 1, 1);
+  if (brush->pressure_size_curve) {
+    BKE_curvemapping_free(brush->pressure_size_curve);
   }
+  brush->pressure_size_curve = BKE_curvemapping_add(1, 0, 0, 1, 1);
   brush_reset_input_curve(brush->pressure_size_curve);
 
-  if (!brush->pressure_strength_curve) {
-    brush->pressure_strength_curve = BKE_curvemapping_add(1, 0, 0, 1, 1);
+  if (brush->pressure_strength_curve) {
+    BKE_curvemapping_free(brush->pressure_strength_curve);
   }
+  brush->pressure_strength_curve = BKE_curvemapping_add(1, 0, 0, 1, 1);
   brush_reset_input_curve(brush->pressure_strength_curve);
 }
 
diff --git a/source/blender/blenloader/intern/versioning_290.c 
b/source/blender/blenloader/intern/versioning_290.c
index 80a6eff30a3..eface1d24fc 100644
--- a/source/blender/blenloader/intern/versioning_290.c
+++ b/source/blender/blenloader/intern/versioning_290.c
@@ -1491,12 +1491,12 @@ void blo_do_versions_290(FileData *fd, Library 
*UNUSED(lib), Main *bmain)
    */
   {
     /* Keep this block, even when empty. */
-    LISTBASE_FOREACH (Brush *, br, &bmain->brushes) {
-      if (!br->pressure_size_curve || !br->pressure_strength_curve) {
+    if (!DNA_struct_elem_find(fd->filesdna, "Brush", "CurveMapping", 
"*pressure_size_curve")) {
+      LISTBASE_FOREACH (Brush *, br, &bmain->brushes) {
         BKE_brush_default_input_curves_set(br);
       }
     }
-    
+
     if (!DNA_struct_find(fd->filesdna, "NodeSetAlpha")) {
       LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
         bNodeTree *nodetree = scene->nodetree;
diff --git a/source/blender/editors/sculpt_paint/sculpt.c 
b/source/blender/editors/sculpt_paint/sculpt.c
index f6fc3199ae7..5ac035b56a2 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -2310,8 +2310,8 @@ static float brush_strength(const Sculpt *sd,
 
   float pressure = BKE_brush_use_alpha_pressure(brush) ? cache->pressure : 
1.0f;
   if (brush->pressure_strength_curve) {
-    BKE_curvemapping_init(brush->pressure_strength_curve);
   }
+  BKE_curvemapping_init(brush->pressure_strength_curve);
   pressure = BKE_brush_use_alpha_pressure(brush) && 
brush->pressure_strength_curve ?
                  BKE_curvemapping_evaluateF(brush->pressure_strength_curve, 0, 
cache->pressure) :
                  pressure;

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to