Alternate fix for brush user count
authorCampbell Barton <ideasman42@gmail.com>
Wed, 10 Jan 2018 08:34:34 +0000 (19:34 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 10 Jan 2018 08:34:34 +0000 (19:34 +1100)
This reverts change to BKE_brush_add,
callers now remove the extra user.

Note this isn't very convenient for callers but
is consistent with other ID types.

In the future we will probably remove this and have new
ID's created with zero users.

source/blender/blenkernel/intern/brush.c
source/blender/blenkernel/intern/paint.c
source/blender/blenloader/intern/versioning_defaults.c
source/blender/editors/sculpt_paint/paint_ops.c
source/blender/makesrna/intern/rna_main_api.c

index 8ad9cbb2625ec32724318096521a82921a12827f..0f09b74133038a09c560df3839daec808233db0f 100644 (file)
@@ -148,12 +148,14 @@ void BKE_brush_init(Brush *brush)
        BKE_brush_curve_preset(brush, CURVE_PRESET_SMOOTH);
 }
 
+/**
+ * \note Resulting brush will have two users: one as a fake user, another is assumed to be used by the caller.
+ .*/
 Brush *BKE_brush_add(Main *bmain, const char *name, short ob_mode)
 {
        Brush *brush;
 
-       /* Use no refcount, fakeuser is added in 'BKE_brush_init' */
-       brush = BKE_libblock_alloc(bmain, ID_BR, name, LIB_ID_CREATE_NO_USER_REFCOUNT);
+       brush = BKE_libblock_alloc(bmain, ID_BR, name, 0);
 
        BKE_brush_init(brush);
 
index 32813ffce25295d2f0551091dfb3d3383a4cd820..d1e9516f6d20addf654ded5bd20f1eed91d9ecb8 100644 (file)
@@ -529,8 +529,10 @@ void BKE_paint_init(Scene *sce, ePaintMode mode, const char col[3])
                short ob_mode = BKE_paint_object_mode_from_paint_mode(mode);
                brush = BKE_brush_first_search(G.main, ob_mode);
 
-               if (!brush)
+               if (!brush) {
                        brush = BKE_brush_add(G.main, "Brush", ob_mode);
+                       id_us_min(&brush->id);  /* fake user only */
+               }
                BKE_paint_brush_set(paint, brush);
        }
 
index 3d3e73eb4705557e58bb6d769d0eeb86f7ef0b49..23ec1cd3231f9a4eeef03b164a1b228a28a71efa 100644 (file)
@@ -242,6 +242,7 @@ void BLO_update_defaults_startup_blend(Main *bmain)
                br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Fill");
                if (!br) {
                        br = BKE_brush_add(bmain, "Fill", OB_MODE_TEXTURE_PAINT);
+                       id_us_min(&br->id);  /* fake user only */
                        br->imagepaint_tool = PAINT_TOOL_FILL;
                        br->ob_mode = OB_MODE_TEXTURE_PAINT;
                }
@@ -250,12 +251,14 @@ void BLO_update_defaults_startup_blend(Main *bmain)
                br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Average");
                if (!br) {
                        br = BKE_brush_add(bmain, "Average", OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT);
+                       id_us_min(&br->id);  /* fake user only */
                        br->vertexpaint_tool = PAINT_BLEND_AVERAGE;
                        br->ob_mode = OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT;
                }
                br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Smear");
                if (!br) {
                        br = BKE_brush_add(bmain, "Smear", OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT);
+                       id_us_min(&br->id);  /* fake user only */
                        br->vertexpaint_tool = PAINT_BLEND_SMEAR;
                        br->ob_mode = OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT;
                }
index 40210d63566de7a5cb4006024ffbf066d7e58e0e..73cb31bb1bda3eaa901257debb7f59a8947d2a32 100644 (file)
@@ -68,10 +68,13 @@ static int brush_add_exec(bContext *C, wmOperator *UNUSED(op))
        Main *bmain = CTX_data_main(C);
        ePaintMode mode = BKE_paintmode_get_active_from_context(C);
 
-       if (br)
+       if (br) {
                br = BKE_brush_copy(bmain, br);
-       else
+       }
+       else {
                br = BKE_brush_add(bmain, "Brush", BKE_paint_object_mode_from_paint_mode(mode));
+               id_us_min(&br->id);  /* fake user only */
+       }
 
        BKE_paint_brush_set(paint, br);
 
@@ -376,6 +379,7 @@ static int brush_generic_tool_set(Main *bmain, Paint *paint, const int tool,
 
        if (!brush && brush_tool(brush_orig, tool_offset) != tool && create_missing) {
                brush = BKE_brush_add(bmain, tool_name, ob_mode);
+               id_us_min(&brush->id);  /* fake user only */
                brush_tool_set(brush, tool_offset, tool);
                brush->toggle_brush = brush_orig;
        }
index 992e4f034ec985b9b9537842cdda437492e34e4d..7e2ced81a6d1b9ad485372271ee6251b46b08dbd 100644 (file)
@@ -421,8 +421,7 @@ static Brush *rna_Main_brushes_new(Main *bmain, const char *name, int mode)
        rna_idname_validate(name, safe_name);
 
        Brush *brush = BKE_brush_add(bmain, safe_name, mode);
-       /* Brushes have a single fake user, leave this as is. */
-       // id_us_min(&brush->id);
+       id_us_min(&brush->id);
        return brush;
 }