Commit: 7212ebd09f9720883581221be923ae5e97ff5d76
Author: Bastien Montagne
Date:   Mon Jul 11 21:27:15 2016 +0200
Branches: master
https://developer.blender.org/rB7212ebd09f9720883581221be923ae5e97ff5d76

Remove usercount handling from BKE_id_expand_local.

Idea looked good, but we have too much custom situations here (some 
half-fake-sub-ID
being copied with their 'owner', animdata, etc.), let's let datablock copy 
functions
handle that themselves.

Also allows to safely call BKE_id_expand_local from all copy functions now 
(only when
copying linked data).

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

M       source/blender/blenkernel/BKE_library.h
M       source/blender/blenkernel/intern/action.c
M       source/blender/blenkernel/intern/armature.c
M       source/blender/blenkernel/intern/brush.c
M       source/blender/blenkernel/intern/camera.c
M       source/blender/blenkernel/intern/curve.c
M       source/blender/blenkernel/intern/group.c
M       source/blender/blenkernel/intern/image.c
M       source/blender/blenkernel/intern/key.c
M       source/blender/blenkernel/intern/lamp.c
M       source/blender/blenkernel/intern/lattice.c
M       source/blender/blenkernel/intern/library.c
M       source/blender/blenkernel/intern/linestyle.c
M       source/blender/blenkernel/intern/mask.c
M       source/blender/blenkernel/intern/material.c
M       source/blender/blenkernel/intern/mball.c
M       source/blender/blenkernel/intern/mesh.c
M       source/blender/blenkernel/intern/node.c
M       source/blender/blenkernel/intern/object.c
M       source/blender/blenkernel/intern/particle.c
M       source/blender/blenkernel/intern/speaker.c
M       source/blender/blenkernel/intern/text.c
M       source/blender/blenkernel/intern/texture.c
M       source/blender/blenkernel/intern/world.c

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

diff --git a/source/blender/blenkernel/BKE_library.h 
b/source/blender/blenkernel/BKE_library.h
index e633719..d419d25 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -84,7 +84,7 @@ bool id_make_local(struct Main *bmain, struct ID *id, bool 
test);
 bool id_single_user(struct bContext *C, struct ID *id, struct PointerRNA *ptr, 
struct PropertyRNA *prop);
 bool id_copy(struct Main *bmain, struct ID *id, struct ID **newid, bool test);
 void id_sort_by_name(struct ListBase *lb, struct ID *id);
-void BKE_id_expand_local(struct ID *id, const bool do_user_count);
+void BKE_id_expand_local(struct ID *id);
 
 bool new_id(struct ListBase *lb, struct ID *id, const char *name);
 void id_clear_lib_data(struct Main *bmain, struct ID *id);
diff --git a/source/blender/blenkernel/intern/action.c 
b/source/blender/blenkernel/intern/action.c
index 1e5ad81..f7ff126 100644
--- a/source/blender/blenkernel/intern/action.c
+++ b/source/blender/blenkernel/intern/action.c
@@ -113,7 +113,7 @@ void BKE_action_make_local(Main *bmain, bAction *act)
        if (is_local) {
                if (!is_lib) {
                        id_clear_lib_data(bmain, &act->id);
-                       BKE_id_expand_local(&act->id, false);
+                       BKE_id_expand_local(&act->id);
                }
                else {
                        bAction *act_new = BKE_action_copy(bmain, act);
@@ -181,9 +181,8 @@ bAction *BKE_action_copy(Main *bmain, bAction *src)
                }
        }
        
-       BKE_id_expand_local(&dst->id, true);
-
        if (ID_IS_LINKED_DATABLOCK(src)) {
+               BKE_id_expand_local(&dst->id);
                BKE_id_lib_local_paths(bmain, src->id.lib, &dst->id);
        }
 
diff --git a/source/blender/blenkernel/intern/armature.c 
b/source/blender/blenkernel/intern/armature.c
index 47fa0e9..5f564e1 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -162,7 +162,7 @@ void BKE_armature_make_local(Main *bmain, bArmature *arm)
        if (is_local) {
                if (!is_lib) {
                        id_clear_lib_data(bmain, &arm->id);
-                       BKE_id_expand_local(&arm->id, false);
+                       BKE_id_expand_local(&arm->id);
                }
                else {
                        bArmature *arm_new = BKE_armature_copy(bmain, arm);
@@ -219,9 +219,8 @@ bArmature *BKE_armature_copy(Main *bmain, bArmature *arm)
        newArm->act_edbone = NULL;
        newArm->sketch = NULL;
 
-       BKE_id_expand_local(&newArm->id, true);
-
        if (ID_IS_LINKED_DATABLOCK(arm)) {
+               BKE_id_expand_local(&newArm->id);
                BKE_id_lib_local_paths(bmain, arm->id.lib, &newArm->id);
        }
 
diff --git a/source/blender/blenkernel/intern/brush.c 
b/source/blender/blenkernel/intern/brush.c
index 1f48d58..20621fe 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -178,6 +178,15 @@ Brush *BKE_brush_copy(Main *bmain, Brush *brush)
        
        brushn = BKE_libblock_copy(bmain, &brush->id);
 
+       if (brush->mtex.tex)
+               id_us_plus((ID *)brush->mtex.tex);
+
+       if (brush->mask_mtex.tex)
+               id_us_plus((ID *)brush->mask_mtex.tex);
+
+       if (brush->paint_curve)
+               id_us_plus((ID *)brush->paint_curve);
+
        if (brush->icon_imbuf)
                brushn->icon_imbuf = IMB_dupImBuf(brush->icon_imbuf);
 
@@ -188,9 +197,8 @@ Brush *BKE_brush_copy(Main *bmain, Brush *brush)
        /* enable fake user by default */
        id_fake_user_set(&brush->id);
 
-       BKE_id_expand_local(&brushn->id, true);
-
        if (ID_IS_LINKED_DATABLOCK(brush)) {
+               BKE_id_expand_local(&brushn->id);
                BKE_id_lib_local_paths(bmain, brush->id.lib, &brushn->id);
        }
 
@@ -234,7 +242,7 @@ void BKE_brush_make_local(Main *bmain, Brush *brush)
        if (is_local) {
                if (!is_lib) {
                        id_clear_lib_data(bmain, &brush->id);
-                       BKE_id_expand_local(&brush->id, false);
+                       BKE_id_expand_local(&brush->id);
 
                        /* enable fake user by default */
                        id_fake_user_set(&brush->id);
diff --git a/source/blender/blenkernel/intern/camera.c 
b/source/blender/blenkernel/intern/camera.c
index 972057f..ae7aac8 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -99,9 +99,8 @@ Camera *BKE_camera_copy(Main *bmain, Camera *cam)
        
        camn = BKE_libblock_copy(bmain, &cam->id);
 
-       BKE_id_expand_local(&camn->id, true);
-
        if (ID_IS_LINKED_DATABLOCK(cam)) {
+               BKE_id_expand_local(&camn->id);
                BKE_id_lib_local_paths(bmain, cam->id.lib, &camn->id);
        }
 
@@ -126,7 +125,7 @@ void BKE_camera_make_local(Main *bmain, Camera *cam)
        if (is_local) {
                if (!is_lib) {
                        id_clear_lib_data(bmain, &cam->id);
-                       BKE_id_expand_local(&cam->id, false);
+                       BKE_id_expand_local(&cam->id);
                }
                else {
                        Camera *cam_new = BKE_camera_copy(bmain, cam);
diff --git a/source/blender/blenkernel/intern/curve.c 
b/source/blender/blenkernel/intern/curve.c
index db5bbe3..0e634e2 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -177,6 +177,7 @@ Curve *BKE_curve_add(Main *bmain, const char *name, int 
type)
 Curve *BKE_curve_copy(Main *bmain, Curve *cu)
 {
        Curve *cun;
+       int a;
 
        cun = BKE_libblock_copy(bmain, &cu->id);
 
@@ -184,6 +185,9 @@ Curve *BKE_curve_copy(Main *bmain, Curve *cu)
        BKE_nurbList_duplicate(&(cun->nurb), &(cu->nurb));
 
        cun->mat = MEM_dupallocN(cu->mat);
+       for (a = 0; a < cun->totcol; a++) {
+               id_us_plus((ID *)cun->mat[a]);
+       }
 
        cun->str = MEM_dupallocN(cu->str);
        cun->strinfo = MEM_dupallocN(cu->strinfo);
@@ -192,16 +196,19 @@ Curve *BKE_curve_copy(Main *bmain, Curve *cu)
 
        if (cu->key) {
                cun->key = BKE_key_copy(bmain, cu->key);
-               cun->key->id.us = 0;  /* Will be increased again by 
BKE_id_expand_local. */
                cun->key->from = (ID *)cun;
        }
 
        cun->editnurb = NULL;
        cun->editfont = NULL;
 
-       BKE_id_expand_local(&cun->id, true);
+       id_us_plus((ID *)cun->vfont);
+       id_us_plus((ID *)cun->vfontb);
+       id_us_plus((ID *)cun->vfonti);
+       id_us_plus((ID *)cun->vfontbi);
 
        if (ID_IS_LINKED_DATABLOCK(cu)) {
+               BKE_id_expand_local(&cun->id);
                BKE_id_lib_local_paths(bmain, cu->id.lib, &cun->id);
        }
 
@@ -229,6 +236,7 @@ void BKE_curve_make_local(Main *bmain, Curve *cu)
                        if (cu->key) {
                                BKE_key_make_local(bmain, cu->key);
                        }
+                       BKE_id_expand_local(&cu->id);
                }
                else {
                        Curve *cu_new = BKE_curve_copy(bmain, cu);
diff --git a/source/blender/blenkernel/intern/group.c 
b/source/blender/blenkernel/intern/group.c
index 99a8366..11bbd91 100644
--- a/source/blender/blenkernel/intern/group.c
+++ b/source/blender/blenkernel/intern/group.c
@@ -98,6 +98,7 @@ Group *BKE_group_copy(Main *bmain, Group *group)
        groupn->preview = NULL;
 
        if (ID_IS_LINKED_DATABLOCK(group)) {
+               BKE_id_expand_local(&groupn->id);
                BKE_id_lib_local_paths(bmain, group->id.lib, &groupn->id);
        }
 
diff --git a/source/blender/blenkernel/intern/image.c 
b/source/blender/blenkernel/intern/image.c
index ae5c2b8..f6f3897 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -462,6 +462,7 @@ Image *BKE_image_copy(Main *bmain, Image *ima)
        nima->preview = BKE_previewimg_copy(ima->preview);
 
        if (ID_IS_LINKED_DATABLOCK(ima)) {
+               BKE_id_expand_local(&nima->id);
                BKE_id_lib_local_paths(bmain, ima->id.lib, &nima->id);
        }
 
@@ -486,7 +487,7 @@ void BKE_image_make_local(Main *bmain, Image *ima)
        if (is_local) {
                if (!is_lib) {
                        id_clear_lib_data(bmain, &ima->id);
-                       BKE_id_expand_local(&ima->id, false);
+                       BKE_id_expand_local(&ima->id);
                }
                else {
                        Image *ima_new = BKE_image_copy(bmain, ima);
diff --git a/source/blender/blenkernel/intern/key.c 
b/source/blender/blenkernel/intern/key.c
index 2b7968e..e59facd 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -171,6 +171,7 @@ Key *BKE_key_copy(Main *bmain, Key *key)
        }
 
        if (ID_IS_LINKED_DATABLOCK(key)) {
+               BKE_id_expand_local(&keyn->id);
                BKE_id_lib_local_paths(bmain, key->id.lib, &keyn->id);
        }
 
diff --git a/source/blender/blenkernel/intern/lamp.c 
b/source/blender/blenkernel/intern/lamp.c
index 8486281..003b154 100644
--- a/source/blender/blenkernel/intern/lamp.c
+++ b/source/blender/blenkernel/intern/lamp.c
@@ -139,6 +139,7 @@ Lamp *BKE_lamp_copy(Main *bmain, Lamp *la)
        lan->preview = BKE_previewimg_copy(la->preview);
 
        if (ID_IS_LINKED_DATABLOCK(la)) {
+               BKE_id_expand_local(&lan->id);
                BKE_id_lib_local_paths(bmain, la->id.lib, &lan->id);
        }
 
@@ -189,7 +190,7 @@ void BKE_lamp_make_local(Main *bmain, Lamp *la)
        if (is_local) {
                if (!is_lib) {
                        id_clear_lib_data(bmain, &la->id);
-                       BKE_id_expand_local(&la->id, false);
+                       BKE_id_expand_local(&la->id);
                }
                else {
                        Lamp *la_new = BKE_lamp_copy(bmain, la);
diff --git a/source/blender/blenkernel/intern/lattice.c 
b/source/blender/blenkernel/intern/lattice.c
index c2a94ef..67f4926 100644
--- a/source/blender/blenkernel/intern/lattice.c
+++ b/source/blender/blenkernel/intern/lattice.c
@@ -286,7 +286,6 @@ Lattice *BKE_lattice_copy(Main *bmain, Lattice *lt)
 
        if (lt->key) {
                ltn->key = BKE_key_copy(bmain, ltn->key);
-               ltn->key->id.us = 0;  /* Will be increased again by 
BKE_id_expand_local. */
                ltn->key->from = (ID *)ltn;
        }
        
@@ -298,9 +297,8 @@ Lattice *BKE_lattice_copy(Main *bmain, Lattice *lt)
 
        ltn->editlatt = NULL;
 
-       BKE_id_expand_local(&ltn->id, true);
-
        if (ID_IS_LINKED_DATABLOCK(lt)) {
+               BKE_id_expand_local(&ltn->id);
                BKE_id_lib_local_paths(bmain, lt->id.lib, &ltn->id);
        }
 
@@ -353,7 +351,7 @@ void BKE_lattice_make_local(Main *bmain, Lattice *lt)
                        if (lt->key) {
                                BKE_key_make_local(bmain, lt->key);
                        }
-                       BKE_id_expand_local(&lt->id, false);
+                       BKE_id_expand_local(&lt->id);
                }
                else {
                        Lattice *lt_new = BKE_lattice_copy(bmain, lt);
diff --git a/source/blender/blenkernel/intern/library.c 
b/source/blender/blenkernel/intern/library.c
index 678ac66..869e024 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -251,22 +251,11 @@ void id_fake_user_clear(ID *id)
        }
 }
 
-static int id_expand_local_callback(void *user_data, struct ID 
*UNUSED(id_self), struct ID **id_pointer, int cd_flag)
+static int id_expand_local_callback(
+        void *UNUSED(user_data), struct ID *UNUSED(id_self), struct ID 
**id_pointer, int UNUSED(cd_flag))
 {
-       const bool do_user_count = (user_data != NULL);
-
-       /* We tag all ID usages as extern, and increase usercount in case it 
was requested. */
        if (*id_pointer) {
-               if (do_user_count && 

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to