Alternate fix for brush user count

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.
This commit is contained in:
Campbell Barton 2018-01-10 19:34:34 +11:00
parent 3f837341c8
commit bc02c5de49
5 changed files with 17 additions and 7 deletions

View 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);

View 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);
}

View 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;
}

View 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;
}

View 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;
}