Fix T53943: Weight paint crash in new scene
authorCampbell Barton <ideasman42@gmail.com>
Tue, 30 Jan 2018 09:33:20 +0000 (20:33 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 30 Jan 2018 09:33:20 +0000 (20:33 +1100)
source/blender/blenkernel/BKE_paint.h
source/blender/blenkernel/intern/paint.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/sculpt_paint/sculpt.c

index cc02d8b..8e7e69d 100644 (file)
@@ -253,6 +253,7 @@ void BKE_sculpt_update_mesh_elements(struct Scene *scene, struct Sculpt *sd, str
 struct MultiresModifierData *BKE_sculpt_multires_active(struct Scene *scene, struct Object *ob);
 int BKE_sculpt_mask_layers_ensure(struct Object *ob,
                                   struct MultiresModifierData *mmd);
+void BKE_sculpt_toolsettings_data_ensure(struct Scene *scene);
 
 enum {
        SCULPT_MASK_LAYER_CALC_VERT = (1 << 0),
index c6aa9c4..dba2bc7 100644 (file)
@@ -1057,3 +1057,39 @@ int BKE_sculpt_mask_layers_ensure(Object *ob, MultiresModifierData *mmd)
 
        return ret;
 }
+
+void BKE_sculpt_toolsettings_data_ensure(struct Scene *scene)
+{
+       Sculpt *sd = scene->toolsettings->sculpt;
+       if (sd == NULL) {
+               sd = scene->toolsettings->sculpt = MEM_callocN(sizeof(Sculpt), __func__);
+
+               /* Turn on X plane mirror symmetry by default */
+               sd->paint.symmetry_flags |= PAINT_SYMM_X;
+               sd->paint.flags |= PAINT_SHOW_BRUSH;
+
+               /* Make sure at least dyntopo subdivision is enabled */
+               sd->flags |= SCULPT_DYNTOPO_SUBDIVIDE | SCULPT_DYNTOPO_COLLAPSE;
+       }
+
+       if (!sd->detail_size) {
+               sd->detail_size = 12;
+       }
+       if (!sd->detail_percent) {
+               sd->detail_percent = 25;
+       }
+       if (sd->constant_detail == 0.0f) {
+               sd->constant_detail = 3.0f;
+       }
+
+       /* Set sane default tiling offsets */
+       if (!sd->paint.tile_offset[0]) {
+               sd->paint.tile_offset[0] = 1.0f;
+       }
+       if (!sd->paint.tile_offset[1]) {
+               sd->paint.tile_offset[1] = 1.0f;
+       }
+       if (!sd->paint.tile_offset[2]) {
+               sd->paint.tile_offset[2] = 1.0f;
+       }
+}
index a540533..490343a 100644 (file)
@@ -939,6 +939,9 @@ static void do_weight_paint_vertex(
 /* Toggle operator for turning vertex paint mode on or off (copied from sculpt.c) */
 static void vertex_paint_init_session(Scene *scene, Object *ob)
 {
+       /* Create persistent sculpt mode data */
+       BKE_sculpt_toolsettings_data_ensure(scene);
+
        if (ob->sculpt == NULL) {
                ob->sculpt = MEM_callocN(sizeof(SculptSession), "sculpt session");
                BKE_sculpt_update_mesh_elements(scene, scene->toolsettings->sculpt, ob, 0, false);
index 37af173..2468f27 100644 (file)
@@ -5585,8 +5585,10 @@ static void SCULPT_OT_symmetrize(wmOperatorType *ot)
 
 static void sculpt_init_session(Scene *scene, Object *ob)
 {
-       ob->sculpt = MEM_callocN(sizeof(SculptSession), "sculpt session");
+       /* Create persistent sculpt mode data */
+       BKE_sculpt_toolsettings_data_ensure(scene);
 
+       ob->sculpt = MEM_callocN(sizeof(SculptSession), "sculpt session");
        BKE_sculpt_update_mesh_elements(scene, scene->toolsettings->sculpt, ob, 0, false);
 }
 
@@ -5650,31 +5652,6 @@ static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op)
                if (flush_recalc)
                        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
 
-               /* Create persistent sculpt mode data */
-               if (!ts->sculpt) {
-                       ts->sculpt = MEM_callocN(sizeof(Sculpt), "sculpt mode data");
-
-                       /* Turn on X plane mirror symmetry by default */
-                       ts->sculpt->paint.symmetry_flags |= PAINT_SYMM_X;
-                       ts->sculpt->paint.flags |= PAINT_SHOW_BRUSH;
-
-                       /* Make sure at least dyntopo subdivision is enabled */
-                       ts->sculpt->flags |= SCULPT_DYNTOPO_SUBDIVIDE | SCULPT_DYNTOPO_COLLAPSE;
-               }
-
-               if (!ts->sculpt->detail_size)
-                       ts->sculpt->detail_size = 12;
-               if (!ts->sculpt->detail_percent)
-                       ts->sculpt->detail_percent = 25;
-               if (ts->sculpt->constant_detail == 0.0f)
-                       ts->sculpt->constant_detail = 3.0f;
-
-               /* Set sane default tiling offsets */
-               if (!ts->sculpt->paint.tile_offset[0]) ts->sculpt->paint.tile_offset[0] = 1.0f;
-               if (!ts->sculpt->paint.tile_offset[1]) ts->sculpt->paint.tile_offset[1] = 1.0f;
-               if (!ts->sculpt->paint.tile_offset[2]) ts->sculpt->paint.tile_offset[2] = 1.0f;
-
-
                /* Create sculpt mode session data */
                if (ob->sculpt)
                        BKE_sculptsession_free(ob);