From 6e6b79de35fbe5f4cf0c79dcd854827fc0c95499 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 10 Jan 2018 17:45:34 +1100 Subject: Fix brush user count New brushes had 2 users on adding. Caused assert removing them after. --- source/blender/blenkernel/intern/brush.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 230db6dccff..8ad9cbb2625 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -152,7 +152,8 @@ Brush *BKE_brush_add(Main *bmain, const char *name, short ob_mode) { Brush *brush; - brush = BKE_libblock_alloc(bmain, ID_BR, name, 0); + /* Use no refcount, fakeuser is added in 'BKE_brush_init' */ + brush = BKE_libblock_alloc(bmain, ID_BR, name, LIB_ID_CREATE_NO_USER_REFCOUNT); BKE_brush_init(brush); -- cgit v1.2.3 From 3f837341c8f5652f02909d1ebbcf1743ab371847 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 10 Jan 2018 18:31:54 +1100 Subject: Correction to brush user commit RNA API was compensating for the extra user. --- source/blender/makesrna/intern/rna_main_api.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c index 7e2ced81a6d..992e4f034ec 100644 --- a/source/blender/makesrna/intern/rna_main_api.c +++ b/source/blender/makesrna/intern/rna_main_api.c @@ -421,7 +421,8 @@ 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); - id_us_min(&brush->id); + /* Brushes have a single fake user, leave this as is. */ + // id_us_min(&brush->id); return brush; } -- cgit v1.2.3 From bc02c5de497c360449e4de68b3c1432f9bd204de Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 10 Jan 2018 19:34:34 +1100 Subject: 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. --- source/blender/blenkernel/intern/brush.c | 6 ++++-- source/blender/blenkernel/intern/paint.c | 4 +++- source/blender/blenloader/intern/versioning_defaults.c | 3 +++ source/blender/editors/sculpt_paint/paint_ops.c | 8 ++++++-- source/blender/makesrna/intern/rna_main_api.c | 3 +-- 5 files changed, 17 insertions(+), 7 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 8ad9cbb2625..0f09b741330 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -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); diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 32813ffce25..d1e9516f6d2 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -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); } diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c index 3d3e73eb470..23ec1cd3231 100644 --- a/source/blender/blenloader/intern/versioning_defaults.c +++ b/source/blender/blenloader/intern/versioning_defaults.c @@ -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; } diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index 40210d63566..73cb31bb1bd 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -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; } diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c index 992e4f034ec..7e2ced81a6d 100644 --- a/source/blender/makesrna/intern/rna_main_api.c +++ b/source/blender/makesrna/intern/rna_main_api.c @@ -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; } -- cgit v1.2.3 From 18f53d8822518928baceab1407eac195ab9bf817 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 10 Jan 2018 19:57:02 +1100 Subject: Cleanup: comment block alignment --- source/blender/blenkernel/intern/brush.c | 5 +++-- source/blender/blenkernel/intern/deform.c | 2 +- source/blender/blenkernel/intern/image.c | 4 ++-- source/blender/blenlib/intern/rct.c | 2 +- source/blender/bmesh/tools/bmesh_bevel.c | 4 ++-- source/blender/editors/mesh/editmesh_utils.c | 4 ++-- source/blender/editors/sculpt_paint/paint_vertex.c | 2 +- source/blender/editors/sculpt_paint/sculpt_intern.h | 18 +++++++++--------- source/blender/editors/space_view3d/drawanimviz.c | 18 +++++++++--------- .../blender/editors/transform/transform_snap_object.c | 4 ++-- source/blender/makesdna/DNA_userdef_types.h | 2 +- source/blender/windowmanager/intern/wm_stereo.c | 2 +- 12 files changed, 34 insertions(+), 33 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 0f09b741330..8d63c1cfb44 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -150,7 +150,7 @@ void BKE_brush_init(Brush *brush) /** * \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; @@ -1066,7 +1066,8 @@ struct ImBuf *BKE_brush_gen_radial_control_imbuf(Brush *br, bool secondary) for (i = 0; i < side; ++i) { for (j = 0; j < side; ++j) { const int col = texcache[i * side + j]; - im->rect_float[i * side + j] *= (((char *)&col)[0] + ((char *)&col)[1] + ((char *)&col)[2]) / 3.0f / 255.0f; + im->rect_float[i * side + j] *= + (((char *)&col)[0] + ((char *)&col)[1] + ((char *)&col)[2]) / 3.0f / 255.0f; } } diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index eec8d2478da..22ff8bf4bb7 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -625,7 +625,7 @@ float defvert_array_find_weight_safe(const struct MDeformVert *dvert, const int * (i.e. maximum weight, as if no vgroup was selected). * But in case of valid defgroup and NULL dvert data pointer, it means that vgroup **is** valid, * and just totally empty, so we shall return '0.0' value then! - */ + */ if (defgroup == -1) { return 1.0f; } diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 9ba7cc1c679..e3e403251e1 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -112,9 +112,9 @@ static void image_add_view(Image *ima, const char *viewname, const char *filepat /* quick lookup: supports 1 million frames, thousand passes */ #define IMA_MAKE_INDEX(frame, index) (((frame) << 10) + (index)) #define IMA_INDEX_FRAME(index) ((index) >> 10) -/* +#if 0 #define IMA_INDEX_PASS(index) (index & ~1023) -*/ +#endif /* ******** IMAGE CACHE ************* */ diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c index 3adc6b30f6e..764b12431d0 100644 --- a/source/blender/blenlib/intern/rct.c +++ b/source/blender/blenlib/intern/rct.c @@ -128,7 +128,7 @@ bool BLI_rctf_isect_pt_v(const rctf *rect, const float xy[2]) /** * \returns shortest distance from \a rect to x/y (0 if inside) -*/ + */ int BLI_rcti_length_x(const rcti *rect, const int x) { diff --git a/source/blender/bmesh/tools/bmesh_bevel.c b/source/blender/bmesh/tools/bmesh_bevel.c index d00d0d508c7..a1fb13ecdfb 100644 --- a/source/blender/bmesh/tools/bmesh_bevel.c +++ b/source/blender/bmesh/tools/bmesh_bevel.c @@ -1692,7 +1692,7 @@ static void build_boundary_vertex_only(BevelParams *bp, BevVert *bv, bool constr * Special case of build_boundary when a single edge is beveled. * The 'width adjust' part of build_boundary has been done already, * and \a efirst is the first beveled edge at vertex \a bv. -*/ + */ static void build_boundary_terminal_edge(BevelParams *bp, BevVert *bv, EdgeHalf *efirst, bool construct) { MemArena *mem_arena = bp->mem_arena; @@ -4933,7 +4933,7 @@ static void bevel_limit_offset(BevelParams *bp) * so we can just multiply them all by the reduction factor * of the offset to have the effect of recalculating the specs * with the new limited_offset. - */ + */ offset_factor = limited_offset / bp->offset; GHASH_ITER(giter, bp->vert_hash) { bv = BLI_ghashIterator_getValue(&giter); diff --git a/source/blender/editors/mesh/editmesh_utils.c b/source/blender/editors/mesh/editmesh_utils.c index 44aca23e2cc..e407d342603 100644 --- a/source/blender/editors/mesh/editmesh_utils.c +++ b/source/blender/editors/mesh/editmesh_utils.c @@ -397,7 +397,7 @@ void EDBM_mesh_load(Object *ob) * of freed data on scene update, especially in cases when there are dependency * cycles. */ - /* +#if 0 for (Object *other_object = G.main->object.first; other_object != NULL; other_object = other_object->id.next) @@ -406,7 +406,7 @@ void EDBM_mesh_load(Object *ob) BKE_object_free_derived_caches(other_object); } } - */ +#endif } /** diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 7abccf6bf62..6303d700b40 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1188,7 +1188,7 @@ static void vwpaint_update_cache_invariants( cache->invert = mode == BRUSH_STROKE_INVERT; cache->alt_smooth = mode == BRUSH_STROKE_SMOOTH; /* not very nice, but with current events system implementation - * we can't handle brush appearance inversion hotkey separately (sergey) */ + * we can't handle brush appearance inversion hotkey separately (sergey) */ if (cache->invert) ups->draw_inverted = true; else ups->draw_inverted = false; diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h index aaea13ce5d0..5fb9eee805f 100644 --- a/source/blender/editors/sculpt_paint/sculpt_intern.h +++ b/source/blender/editors/sculpt_paint/sculpt_intern.h @@ -119,7 +119,7 @@ typedef struct SculptUndoNode { } SculptUndoNode; /* Factor of brush to have rake point following behind -* (could be configurable but this is reasonable default). */ + * (could be configurable but this is reasonable default). */ #define SCULPT_RAKE_BRUSH_FACTOR 0.25f struct SculptRakeData { @@ -148,7 +148,7 @@ typedef struct SculptThreadedTaskData { /* Data specific to some callbacks. */ /* Note: even if only one or two of those are used at a time, keeping them separated, names help figuring out - * what it is, and memory overhead is ridiculous anyway... */ + * what it is, and memory overhead is ridiculous anyway... */ float flippedbstrength; float angle; float strength; @@ -239,10 +239,10 @@ void sculpt_pbvh_calc_area_normal( float r_area_no[3]); /* Cache stroke properties. Used because -* RNA property lookup isn't particularly fast. -* -* For descriptions of these settings, check the operator properties. -*/ + * RNA property lookup isn't particularly fast. + * + * For descriptions of these settings, check the operator properties. + */ typedef struct StrokeCache { /* Invariants */ @@ -296,13 +296,13 @@ typedef struct StrokeCache { float view_normal[3]; /* sculpt_normal gets calculated by calc_sculpt_normal(), then the - * sculpt_normal_symm gets updated quickly with the usual symmetry - * transforms */ + * sculpt_normal_symm gets updated quickly with the usual symmetry + * transforms */ float sculpt_normal[3]; float sculpt_normal_symm[3]; /* Used for area texture mode, local_mat gets calculated by - * calc_brush_local_mat() and used in tex_strength(). */ + * calc_brush_local_mat() and used in tex_strength(). */ float brush_local_mat[4][4]; float plane_offset[3]; /* used to shift the plane around when doing tiled strokes */ diff --git a/source/blender/editors/space_view3d/drawanimviz.c b/source/blender/editors/space_view3d/drawanimviz.c index f0e65f84205..a99ac0d46a5 100644 --- a/source/blender/editors/space_view3d/drawanimviz.c +++ b/source/blender/editors/space_view3d/drawanimviz.c @@ -76,15 +76,15 @@ void draw_motion_paths_init(View3D *v3d, ARegion *ar) } /* set color -* - more intense for active/selected bones, less intense for unselected bones -* - black for before current frame, green for current frame, blue for after current frame -* - intensity decreases as distance from current frame increases -* -* If the user select custom color, the color is replaced for the color selected in UI panel -* - 75% Darker color is used for previous frames -* - 50% Darker color for current frame -* - User selected color for next frames -*/ + * - more intense for active/selected bones, less intense for unselected bones + * - black for before current frame, green for current frame, blue for after current frame + * - intensity decreases as distance from current frame increases + * + * If the user select custom color, the color is replaced for the color selected in UI panel + * - 75% Darker color is used for previous frames + * - 50% Darker color for current frame + * - User selected color for next frames + */ static void set_motion_path_color(Scene *scene, bMotionPath *mpath, int i, short sel, int sfra, int efra, float prev_color[3], float frame_color[3], float next_color[3]) { diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c index 63bdf3ac010..eafb3650d36 100644 --- a/source/blender/editors/transform/transform_snap_object.c +++ b/source/blender/editors/transform/transform_snap_object.c @@ -136,7 +136,7 @@ struct SnapObjectContext { /* -------------------------------------------------------------------- */ /** Common utilities -* \{ */ + * \{ */ typedef void(*IterSnapObjsCallback)(SnapObjectContext *sctx, bool is_obedit, Object *ob, float obmat[4][4], void *data); @@ -260,7 +260,7 @@ static int dm_looptri_to_poly_index(DerivedMesh *dm, const MLoopTri *lt); /* -------------------------------------------------------------------- */ /** \name Ray Cast Funcs -* \{ */ + * \{ */ /* Store all ray-hits * Support for storing all depths, not just the first (raycast 'all') */ diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index cddb1e06b8c..84818fe79c2 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -816,7 +816,7 @@ typedef enum eColorPicker_Types { } eColorPicker_Types; /* timecode display styles - * UserDef.timecode_style */ + * UserDef.timecode_style */ typedef enum eTimecodeStyles { /* as little info as is necessary to show relevant info * with '+' to denote the frames diff --git a/source/blender/windowmanager/intern/wm_stereo.c b/source/blender/windowmanager/intern/wm_stereo.c index 66ebf18c9e1..55fe2ec846c 100644 --- a/source/blender/windowmanager/intern/wm_stereo.c +++ b/source/blender/windowmanager/intern/wm_stereo.c @@ -347,7 +347,7 @@ bool WM_stereo3d_enabled(wmWindow *win, bool skip_stereo3d_check) /** * If needed, this adjusts \a r_mouse_xy so that drawn cursor and handled mouse position are matching visually. -*/ + */ void wm_stereo3d_mouse_offset_apply(wmWindow *win, int *r_mouse_xy) { if (!WM_stereo3d_enabled(win, false)) -- cgit v1.2.3