Remove usercount handling from BKE_id_expand_local.
authorBastien Montagne <montagne29@wanadoo.fr>
Mon, 11 Jul 2016 19:27:15 +0000 (21:27 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Mon, 11 Jul 2016 19:30:02 +0000 (21:30 +0200)
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).

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

index e63371900bf318fb8280f06f73e943e2e1493148..d419d25747181bcc32478fdaed7f29d9d8101a78 100644 (file)
@@ -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);
index 1e5ad81773d2a5990ce129f2a93f31aaa8669c23..f7ff1261c8a8b520be97d7dcbc4ea9f1e58d48fd 100644 (file)
@@ -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);
        }
 
index 47fa0e9ca7fa0c69a26c62d1c582654183df016c..5f564e1c4d2fc8682ad679362ebb44bdf6828ed1 100644 (file)
@@ -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);
        }
 
index 1f48d5835b7df966b7798852489266dc68f2a566..20621feac6cde3ddb087480da41e216190f12d58 100644 (file)
@@ -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);
index 972057fd2dd03f8db8d43051abd64850ba8e1f64..ae7aac8b54fcd3229d778401198430f7f6cf0942 100644 (file)
@@ -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);
index db5bbe307599013c1ce5be88e79e62b3bc9f6e87..0e634e21ea3d00321c629cf4d459ff431e9c6740 100644 (file)
@@ -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);
index 99a83665db7b17e6df5adba23e8a772d988acefa..11bbd91e9c9e9e16269024668a75496739407311 100644 (file)
@@ -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);
        }
 
index ae5c2b80c2130c4c7d52cc4ac91f53e14efe0b7a..f6f389774026b031f774645c448c7b798375e238 100644 (file)
@@ -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);
index 2b7968eec1d7081679e4d58b79c137d2a2bc1aeb..e59facd3c39d6034efd91fea0641af23d3384aca 100644 (file)
@@ -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);
        }
 
index 84862817ce30f26ae2f628229b534c3f2fd4b25e..003b154a70b0c65baaec8085d96d68c444e2b806 100644 (file)
@@ -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);
index c2a94efb963d230242ceaaeaed84618a49988a82..67f49266efc829bbd5d1aa12b6cb1107707e0df8 100644 (file)
@@ -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);
index 678ac662ae3052341f0c72836c72affe1d0793e0..869e02448eac326cc8743dd73e7275974b67488f 100644 (file)
@@ -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 && (cd_flag & IDWALK_USER) &&
-                   /* XXX This is a hack - animdata copying needs a good check and cleanup, it's done with way too much
-                    * various functions currently, so for now we assume actions' usercount is already handled here... */
-                   (GS((*id_pointer)->name) != ID_AC))
-               {
-                       id_us_plus(*id_pointer);
-               }
-               else {
-                       id_lib_extern(*id_pointer);
-               }
+               id_lib_extern(*id_pointer);
        }
 
        return IDWALK_RET_NOP;
@@ -274,12 +263,10 @@ static int id_expand_local_callback(void *user_data, struct ID *UNUSED(id_self),
 
 /**
  * Expand ID usages of given id as 'extern' (and no more indirect) linked data. Used by ID copy/make_local functions.
- *
- * \param do_user_count If true, increase usercount of refcounted datablocks used by given id (use it with copied id).
  */
-void BKE_id_expand_local(struct ID *id, const bool do_user_count)
+void BKE_id_expand_local(ID *id)
 {
-       BKE_library_foreach_ID_link(id, id_expand_local_callback, SET_INT_IN_POINTER((int)do_user_count), 0);
+       BKE_library_foreach_ID_link(id, id_expand_local_callback, NULL, 0);
 }
 
 /* calls the appropriate make_local method for the block, unless test. Returns true
index 12fb42bea5fa104f00f64846951fd19c02b270d4..c4a0d0074fbc31bd189d7a483c1a0a7f629f3933 100644 (file)
@@ -219,6 +219,7 @@ FreestyleLineStyle *BKE_linestyle_copy(struct Main *bmain, FreestyleLineStyle *l
                BKE_linestyle_geometry_modifier_copy(new_linestyle, m);
 
        if (ID_IS_LINKED_DATABLOCK(linestyle)) {
+               BKE_id_expand_local(&new_linestyle->id);
                BKE_id_lib_local_paths(bmain, linestyle->id.lib, &new_linestyle->id);
        }
 
index b5bb57ad123c62c07a8416579bfaeec5bd1e352a..9e070bbef228c5f56339c9278686413e20bf7634 100644 (file)
@@ -854,6 +854,7 @@ Mask *BKE_mask_copy(Main *bmain, Mask *mask)
        id_fake_user_set(&mask->id);
 
        if (ID_IS_LINKED_DATABLOCK(mask)) {
+               BKE_id_expand_local(&mask_new->id);
                BKE_id_lib_local_paths(bmain, mask->id.lib, &mask_new->id);
        }
 
index 5583702aab38b6e80c233a7128d0c76e262b641e..17811893c03c770101c9dcac77c73890344e92a2 100644 (file)
@@ -246,8 +246,9 @@ Material *BKE_material_copy(Main *bmain, Material *ma)
        man->preview = BKE_previewimg_copy(ma->preview);
 
        BLI_listbase_clear(&man->gpumaterial);
-       
+
        if (ID_IS_LINKED_DATABLOCK(ma)) {
+               BKE_id_expand_local(&man->id);
                BKE_id_lib_local_paths(bmain, ma->id.lib, &man->id);
        }
 
@@ -302,7 +303,7 @@ void BKE_material_make_local(Main *bmain, Material *ma)
        if (is_local) {
                if (!is_lib) {
                        id_clear_lib_data(bmain, &ma->id);
-                       BKE_id_expand_local(&ma->id, false);
+                       BKE_id_expand_local(&ma->id);
                }
                else {
                        Material *ma_new = BKE_material_copy(bmain, ma);
index b65df04804d6b1d0bbe14b53f7c14cab06c7ecef..9a0a6e3540ceb74eb8daec1ae5706bd84e7530e0 100644 (file)
@@ -105,19 +105,22 @@ MetaBall *BKE_mball_add(Main *bmain, const char *name)
 MetaBall *BKE_mball_copy(Main *bmain, MetaBall *mb)
 {
        MetaBall *mbn;
+       int a;
        
        mbn = BKE_libblock_copy(bmain, &mb->id);
 
        BLI_duplicatelist(&mbn->elems, &mb->elems);
        
        mbn->mat = MEM_dupallocN(mb->mat);
+       for (a = 0; a < mbn->totcol; a++) {
+               id_us_plus((ID *)mbn->mat[a]);
+       }
 
        mbn->editelems = NULL;
        mbn->lastelem = NULL;
        
-       BKE_id_expand_local(&mbn->id, true);
-
        if (ID_IS_LINKED_DATABLOCK(mb)) {
+               BKE_id_expand_local(&mbn->id);
                BKE_id_lib_local_paths(bmain, mb->id.lib, &mbn->id);
        }
 
@@ -142,7 +145,7 @@ void BKE_mball_make_local(Main *bmain, MetaBall *mb)
        if (is_local) {
                if (!is_lib) {
                        id_clear_lib_data(bmain, &mb->id);
-                       BKE_id_expand_local(&mb->id, false);
+                       BKE_id_expand_local(&mb->id);
                }
                else {
                        MetaBall *mb_new = BKE_mball_copy(bmain, mb);
index 66adea04f67849a95b65aa0e5a2913718912a44d..787b990573424f06cae913bb41952bbff709459c 100644 (file)
@@ -496,11 +496,16 @@ Mesh *BKE_mesh_add(Main *bmain, const char *name)
 Mesh *BKE_mesh_copy(Main *bmain, Mesh *me)
 {
        Mesh *men;
+       int a;
        const int do_tessface = ((me->totface != 0) && (me->totpoly == 0)); /* only do tessface if we have no polys */
        
        men = BKE_libblock_copy(bmain, &me->id);
        
        men->mat = MEM_dupallocN(me->mat);
+       for (a = 0; a < men->totcol; a++) {
+               id_us_plus((ID *)men->mat[a]);
+       }
+       id_us_plus((ID *)men->texcomesh);
 
        CustomData_copy(&me->vdata, &men->vdata, CD_MASK_MESH, CD_DUPLICATE, men->totvert);
        CustomData_copy(&me->edata, &men->edata, CD_MASK_MESH, CD_DUPLICATE, men->totedge);
@@ -522,13 +527,11 @@ Mesh *BKE_mesh_copy(Main *bmain, Mesh *me)
 
        if (me->key) {
                men->key = BKE_key_copy(bmain, me->key);
-               men->id.us = 0;  /* Will be increased again by BKE_id_expand_local. */
                men->key->from = (ID *)men;
        }
 
-       BKE_id_expand_local(&men->id, true);
-
        if (ID_IS_LINKED_DATABLOCK(me)) {
+               BKE_id_expand_local(&men->id);
                BKE_id_lib_local_paths(bmain, me->id.lib, &men->id);
        }
 
@@ -573,7 +576,7 @@ void BKE_mesh_make_local(Main *bmain, Mesh *me)
                        if (me->key) {
                                BKE_key_make_local(bmain, me->key);
                        }
-                       BKE_id_expand_local(&me->id, false);
+                       BKE_id_expand_local(&me->id);
                }
                else {
                        Mesh *me_new = BKE_mesh_copy(bmain, me);
index a9c0e80d815765d9fe97dc598fa295e4edcd1744..296a00388c48458bb4ba0cfad486d667f8dd26f5 100644 (file)
@@ -1292,6 +1292,7 @@ static bNodeTree *ntreeCopyTree_internal(bNodeTree *ntree, Main *bmain, bool ski
        newtree->interface_type = NULL;
        
        if (ID_IS_LINKED_DATABLOCK(ntree)) {
+               BKE_id_expand_local(&newtree->id);
                BKE_id_lib_local_paths(bmain, ntree->id.lib, &newtree->id);
        }
 
@@ -1968,7 +1969,7 @@ void ntreeMakeLocal(Main *bmain, bNodeTree *ntree, bool id_in_mainlist)
        if (is_local) {
                if (!is_lib) {
                        id_clear_lib_data_ex(bmain, (ID *)ntree, id_in_mainlist);
-                       BKE_id_expand_local(&ntree->id, false);
+                       BKE_id_expand_local(&ntree->id);
                }
                else {
                        bNodeTree *ntree_new = ntreeCopyTree(bmain, ntree);
index 1d2f2ab5ddf84641ee6afb70b31b42757ba5e312..30a193506a61aed1d4c596c90e2ba2d01252eeae 100644 (file)
@@ -1166,11 +1166,11 @@ Object *BKE_object_copy_ex(Main *bmain, Object *ob, bool copy_caches)
 
        copy_object_lod(obn, ob);
        
-
        /* Copy runtime surve data. */
        obn->curve_cache = NULL;
 
        if (ID_IS_LINKED_DATABLOCK(ob)) {
+               BKE_id_expand_local(&obn->id);
                BKE_id_lib_local_paths(bmain, ob->id.lib, &obn->id);
        }
 
@@ -1204,7 +1204,7 @@ void BKE_object_make_local(Main *bmain, Object *ob)
        if (is_local) {
                if (!is_lib) {
                        id_clear_lib_data(bmain, &ob->id);
-                       BKE_id_expand_local(&ob->id, false);
+                       BKE_id_expand_local(&ob->id);
                }
                else {
                        Object *ob_new = BKE_object_copy(bmain, ob);
index f50f8cfb4cbeec6b199ebedafbd4cfb88c07cd0c..934c5b9ff066c7dab92f9101ee316eb8907aa0a6 100644 (file)
@@ -3329,14 +3329,14 @@ ParticleSettings *BKE_particlesettings_copy(Main *bmain, ParticleSettings *part)
                if (part->mtex[a]) {
                        partn->mtex[a] = MEM_mallocN(sizeof(MTex), "psys_copy_tex");
                        memcpy(partn->mtex[a], part->mtex[a], sizeof(MTex));
+                       id_us_plus((ID *)partn->mtex[a]->tex);
                }
        }
 
        BLI_duplicatelist(&partn->dupliweights, &part->dupliweights);
        
-       BKE_id_expand_local(&partn->id, true);
-
        if (ID_IS_LINKED_DATABLOCK(part)) {
+               BKE_id_expand_local(&partn->id);
                BKE_id_lib_local_paths(bmain, part->id.lib, &partn->id);
        }
 
@@ -3361,7 +3361,7 @@ void BKE_particlesettings_make_local(Main *bmain, ParticleSettings *part)
        if (is_local) {
                if (!is_lib) {
                        id_clear_lib_data(bmain, &part->id);
-                       BKE_id_expand_local(&part->id, false);
+                       BKE_id_expand_local(&part->id);
                }
                else {
                        ParticleSettings *part_new = BKE_particlesettings_copy(bmain, part);
index 8fb12d5db167ecbc5736ba8a7d070d69352e4b92..a91d86571796ec1a288dc28c096a2d6d80efd0c3 100644 (file)
@@ -74,9 +74,11 @@ Speaker *BKE_speaker_copy(Main *bmain, Speaker *spk)
 
        spkn = BKE_libblock_copy(bmain, &spk->id);
 
-       BKE_id_expand_local(&spkn->id, true);
+       if (spkn->sound)
+               id_us_plus(&spkn->sound->id);
 
        if (ID_IS_LINKED_DATABLOCK(spk)) {
+               BKE_id_expand_local(&spkn->id);
                BKE_id_lib_local_paths(G.main, spk->id.lib, &spkn->id);
        }
 
@@ -101,7 +103,7 @@ void BKE_speaker_make_local(Main *bmain, Speaker *spk)
        if (is_local) {
                if (!is_lib) {
                        id_clear_lib_data(bmain, &spk->id);
-                       BKE_id_expand_local(&spk->id, false);
+                       BKE_id_expand_local(&spk->id);
                }
                else {
                        Speaker *spk_new = BKE_speaker_copy(bmain, spk);
index 6beaba1b41c2fe50787b76c823a33e9e4a171f06..269d6d32b3121fbc39af7e5de137e46fbd543526 100644 (file)
@@ -492,6 +492,7 @@ Text *BKE_text_copy(Main *bmain, Text *ta)
        init_undo_text(tan);
 
        if (ID_IS_LINKED_DATABLOCK(ta)) {
+               BKE_id_expand_local(&tan->id);
                BKE_id_lib_local_paths(bmain, ta->id.lib, &tan->id);
        }
 
index a5088e94adad89f7b8a05747e81fc2de23be4666..e34d632f2caa2c7a00f4665ce0e96c7df3d8abb7 100644 (file)
@@ -872,12 +872,13 @@ Tex *BKE_texture_copy(Main *bmain, Tex *tex)
                texn->nodetree = ntreeCopyTree(bmain, tex->nodetree);
        }
        
+       texn->preview = BKE_previewimg_copy(tex->preview);
+
        if (ID_IS_LINKED_DATABLOCK(tex)) {
+               BKE_id_expand_local(&texn->id);
                BKE_id_lib_local_paths(bmain, tex->id.lib, &texn->id);
        }
 
-       texn->preview = BKE_previewimg_copy(tex->preview);
-
        return texn;
 }
 
@@ -935,7 +936,7 @@ void BKE_texture_make_local(Main *bmain, Tex *tex)
        if (is_local) {
                if (!is_lib) {
                        id_clear_lib_data(bmain, &tex->id);
-                       BKE_id_expand_local(&tex->id, false);
+                       BKE_id_expand_local(&tex->id);
                }
                else {
                        Tex *tex_new = BKE_texture_copy(bmain, tex);
index ca9ff889e2df949f0a453ae3bad1b66cc048d94d..9795a8174f8eb5be2704f7b9b4b7cbb666af7b67 100644 (file)
@@ -143,6 +143,7 @@ World *BKE_world_copy(Main *bmain, World *wrld)
        BLI_listbase_clear(&wrldn->gpumaterial);
 
        if (ID_IS_LINKED_DATABLOCK(wrld)) {
+               BKE_id_expand_local(&wrldn->id);
                BKE_id_lib_local_paths(bmain, wrld->id.lib, &wrldn->id);
        }
 
@@ -193,7 +194,7 @@ void BKE_world_make_local(Main *bmain, World *wrld)
        if (is_local) {
                if (!is_lib) {
                        id_clear_lib_data(bmain, &wrld->id);
-                       BKE_id_expand_local(&wrld->id, false);
+                       BKE_id_expand_local(&wrld->id);
                }
                else {
                        World *wrld_new = BKE_world_copy(bmain, wrld);