Cleanup: avoid incrementing/decrementing id->us outside of BKE_library.
authorBastien Montagne <montagne29@wanadoo.fr>
Mon, 9 Nov 2015 18:47:10 +0000 (19:47 +0100)
committerBastien Montagne <montagne29@wanadoo.fr>
Mon, 9 Nov 2015 20:00:53 +0000 (21:00 +0100)
We have callbacks for that, they also do some checks and help ensure things are done
correctly. Only place where this is assumed not true is blenloader (since here we
may affect refcount of library IDs as well...).

59 files changed:
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/anim_sys.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/effect.c
source/blender/blenkernel/intern/font.c
source/blender/blenkernel/intern/freestyle.c
source/blender/blenkernel/intern/idprop.c
source/blender/blenkernel/intern/image.c
source/blender/blenkernel/intern/ipo.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/movieclip.c
source/blender/blenkernel/intern/nla.c
source/blender/blenkernel/intern/node.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/particle.c
source/blender/blenkernel/intern/scene.c
source/blender/blenkernel/intern/sequencer.c
source/blender/blenkernel/intern/sound.c
source/blender/blenkernel/intern/speaker.c
source/blender/blenkernel/intern/texture.c
source/blender/blenkernel/intern/world.c
source/blender/collada/DocumentImporter.cpp
source/blender/collada/MeshImporter.cpp
source/blender/editors/curve/editcurve.c
source/blender/editors/curve/editfont.c
source/blender/editors/mesh/meshtools.c
source/blender/editors/object/object_add.c
source/blender/editors/object/object_edit.c
source/blender/editors/object/object_relations.c
source/blender/editors/physics/particle_object.c
source/blender/editors/render/render_shading.c
source/blender/editors/sound/sound_ops.c
source/blender/editors/space_action/action_data.c
source/blender/editors/space_clip/clip_ops.c
source/blender/editors/space_image/image_ops.c
source/blender/editors/space_logic/logic_window.c
source/blender/editors/space_nla/nla_edit.c
source/blender/editors/space_node/drawnode.c
source/blender/editors/space_node/node_add.c
source/blender/editors/space_node/node_edit.c
source/blender/editors/space_node/node_templates.c
source/blender/editors/space_outliner/outliner_tools.c
source/blender/editors/space_sequencer/sequencer_edit.c
source/blender/editors/transform/transform_generics.c
source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
source/blender/makesrna/intern/rna_object_force.c
source/blender/makesrna/intern/rna_particle.c
source/blender/makesrna/intern/rna_scene.c
source/gameengine/Converter/KX_BlenderSceneConverter.cpp

index a5a29f667e5981e35b1d4319e48b46fe836f8b3e..3c83fbe6a0112a8e05c5f9b82d50a1cf76c37013 100644 (file)
@@ -52,6 +52,7 @@
 #include "BKE_cdderivedmesh.h"
 #include "BKE_editmesh.h"
 #include "BKE_key.h"
+#include "BKE_library.h"
 #include "BKE_material.h"
 #include "BKE_modifier.h"
 #include "BKE_mesh.h"
@@ -800,7 +801,8 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob, CustomDataMask mask, bool
         * stack*/
        if (tmp.totvert != me->totvert && !did_shapekeys && me->key) {
                printf("%s: YEEK! this should be recoded! Shape key loss!: ID '%s'\n", __func__, tmp.id.name);
-               if (tmp.key) tmp.key->id.us--;
+               if (tmp.key)
+                       id_us_min(&tmp.key->id);
                tmp.key = NULL;
        }
 
index 8010d3450cb7d9960c1986d2d599b3a52e5d7a6f..2ddf01433eb97bb7830279583e71e7200212a4d8 100644 (file)
@@ -229,10 +229,10 @@ void BKE_animdata_free(ID *id)
                if (adt) {
                        /* unlink action (don't free, as it's in its own list) */
                        if (adt->action)
-                               adt->action->id.us--;
+                               id_us_min(&adt->action->id);
                        /* same goes for the temporarily displaced action */
                        if (adt->tmpact)
-                               adt->tmpact->id.us--;
+                               id_us_min(&adt->tmpact->id);
                                
                        /* free nla data */
                        free_nladata(&adt->nla_tracks);
index fde25784c229cbf284eb3e5c7cfba88c62500757..0d757246b1c631f93ad1f58b9de074faf97e3547 100644 (file)
@@ -169,8 +169,8 @@ void BKE_armature_make_local(bArmature *arm)
                        if (ob->data == arm) {
                                if (ob->id.lib == NULL) {
                                        ob->data = arm_new;
-                                       arm_new->id.us++;
-                                       arm->id.us--;
+                                       id_us_plus(&arm_new->id);
+                                       id_us_min(&arm->id);
                                }
                        }
                }
index 95b65f52bd04938e18da060d79847a660dbeecec..201750df5a735c160e9c5de2ecd585583ffc3ce7 100644 (file)
@@ -195,7 +195,7 @@ Brush *BKE_brush_copy(Brush *brush)
        /* enable fake user by default */
        if (!(brushn->id.flag & LIB_FAKEUSER)) {
                brushn->id.flag |= LIB_FAKEUSER;
-               brushn->id.us++;
+               id_us_plus(&brushn->id);
        }
        
        if (brush->id.lib) {
@@ -282,7 +282,7 @@ void BKE_brush_make_local(Brush *brush)
                /* enable fake user by default */
                if (!(brush->id.flag & LIB_FAKEUSER)) {
                        brush->id.flag |= LIB_FAKEUSER;
-                       brush->id.us++;
+                       id_us_plus(&brush->id);
                }
        }
        else if (is_local && is_lib) {
@@ -505,7 +505,7 @@ int BKE_brush_texture_set_nr(Brush *brush, int nr)
        if (idtest == NULL) { /* new tex */
                if (id) idtest = (ID *)BKE_texture_copy((Tex *)id);
                else idtest = (ID *)BKE_texture_add(G.main, "Tex");
-               idtest->us--;
+               id_us_min(idtest);
        }
        if (idtest != id) {
                BKE_brush_texture_delete(brush);
@@ -522,7 +522,7 @@ int BKE_brush_texture_set_nr(Brush *brush, int nr)
 int BKE_brush_texture_delete(Brush *brush)
 {
        if (brush->mtex.tex)
-               brush->mtex.tex->id.us--;
+               id_us_min(&brush->mtex.tex->id);
 
        return 1;
 }
@@ -548,7 +548,7 @@ int BKE_brush_clone_image_set_nr(Brush *brush, int nr)
 int BKE_brush_clone_image_delete(Brush *brush)
 {
        if (brush && brush->clone.image) {
-               brush->clone.image->id.us--;
+               id_us_min(&brush->clone.image->id);
                brush->clone.image = NULL;
                return 1;
        }
index 46b74c5896546d838d55e4179d54f5c7eb861974..73b1f0e53f6283e710f3740221986776b3f0e6c2 100644 (file)
@@ -143,8 +143,8 @@ void BKE_camera_make_local(Camera *cam)
                        if (ob->data == cam) {
                                if (ob->id.lib == NULL) {
                                        ob->data = cam_new;
-                                       cam_new->id.us++;
-                                       cam->id.us--;
+                                       id_us_plus(&cam_new->id);
+                                       id_us_min(&cam->id);
                                }
                        }
                }
index 3e0bdbe31af1a0936cfda428af78005630c22987..22358256f8c400ed7c4cdd95020ce48636cfb799 100644 (file)
@@ -74,27 +74,28 @@ void BKE_curve_unlink(Curve *cu)
        int a;
 
        for (a = 0; a < cu->totcol; a++) {
-               if (cu->mat[a]) cu->mat[a]->id.us--;
+               if (cu->mat[a])
+                       id_us_min(&cu->mat[a]->id);
                cu->mat[a] = NULL;
        }
        if (cu->vfont)
-               cu->vfont->id.us--;
+               id_us_min(&cu->vfont->id);
        cu->vfont = NULL;
 
        if (cu->vfontb)
-               cu->vfontb->id.us--;
+               id_us_min(&cu->vfontb->id);
        cu->vfontb = NULL;
 
        if (cu->vfonti)
-               cu->vfonti->id.us--;
+               id_us_min(&cu->vfonti->id);
        cu->vfonti = NULL;
 
        if (cu->vfontbi)
-               cu->vfontbi->id.us--;
+               id_us_min(&cu->vfontbi->id);
        cu->vfontbi = NULL;
 
        if (cu->key)
-               cu->key->id.us--;
+               id_us_min(&cu->key->id);
        cu->key = NULL;
 }
 
@@ -305,8 +306,8 @@ void BKE_curve_make_local(Curve *cu)
                        if (ob->data == cu) {
                                if (ob->id.lib == NULL) {
                                        ob->data = cu_new;
-                                       cu_new->id.us++;
-                                       cu->id.us--;
+                                       id_us_plus(&cu_new->id);
+                                       id_us_min(&cu->id);
                                }
                        }
                }
index e66fa86c4b10df00b32dd17c6582070351e6338e..30696012221c4b00b9cb4cc2dc8d9ece1c0a8590 100644 (file)
@@ -64,6 +64,7 @@
 #include "BKE_cdderivedmesh.h"
 #include "BKE_effect.h"
 #include "BKE_global.h"
+#include "BKE_library.h"
 #include "BKE_modifier.h"
 #include "BKE_object.h"
 #include "BKE_particle.h"
@@ -139,7 +140,7 @@ void free_partdeflect(PartDeflect *pd)
                return;
 
        if (pd->tex)
-               pd->tex->id.us--;
+               id_us_min(&pd->tex->id);
 
        if (pd->rng)
                BLI_rng_free(pd->rng);
index b12e16d95024cb7386d3a8c6ef8afe2283996920..e8bfa27c6625dd5e86680df8ea51a678b98967cf 100644 (file)
@@ -293,7 +293,7 @@ VFont *BKE_vfont_load_exists_ex(struct Main *bmain, const char *filepath, bool *
                BLI_path_abs(strtest, ID_BLEND_PATH(bmain, &vfont->id));
 
                if (BLI_path_cmp(strtest, str) == 0) {
-                       vfont->id.us++;  /* officially should not, it doesn't link here! */
+                       id_us_plus(&vfont->id);  /* officially should not, it doesn't link here! */
                        if (r_exists)
                                *r_exists = true;
                        return vfont;
index f6c4263cff7f7abc8134fb2eee55b3246eedc9cb..3a15be5a09d61d3fef44cf4cf5d2cd4e1d04ba13 100644 (file)
@@ -35,6 +35,7 @@
 #include "DNA_group_types.h"
 
 #include "BKE_freestyle.h"
+#include "BKE_library.h"
 #include "BKE_linestyle.h"
 
 #include "BLI_blenlib.h"
@@ -65,11 +66,11 @@ void BKE_freestyle_config_free(FreestyleConfig *config)
 
        for (lineset = (FreestyleLineSet *)config->linesets.first; lineset; lineset = lineset->next) {
                if (lineset->group) {
-                       lineset->group->id.us--;
+                       id_us_min(&lineset->group->id);
                        lineset->group = NULL;
                }
                if (lineset->linestyle) {
-                       lineset->linestyle->id.us--;
+                       id_us_min(&lineset->linestyle->id);
                        lineset->linestyle = NULL;
                }
        }
@@ -107,7 +108,7 @@ static void copy_lineset(FreestyleLineSet *new_lineset, FreestyleLineSet *linese
 {
        new_lineset->linestyle = lineset->linestyle;
        if (new_lineset->linestyle)
-               new_lineset->linestyle->id.us++;
+               id_us_plus(&new_lineset->linestyle->id);
        new_lineset->flags = lineset->flags;
        new_lineset->selection = lineset->selection;
        new_lineset->qi = lineset->qi;
@@ -117,7 +118,7 @@ static void copy_lineset(FreestyleLineSet *new_lineset, FreestyleLineSet *linese
        new_lineset->exclude_edge_types = lineset->exclude_edge_types;
        new_lineset->group = lineset->group;
        if (new_lineset->group) {
-               new_lineset->group->id.us++;
+               id_us_plus(&new_lineset->group->id);
        }
        strcpy(new_lineset->name, lineset->name);
 }
@@ -215,10 +216,10 @@ bool BKE_freestyle_lineset_delete(FreestyleConfig *config, FreestyleLineSet *lin
        if (BLI_findindex(&config->linesets, lineset) == -1)
                return false;
        if (lineset->group) {
-               lineset->group->id.us--;
+               id_us_min(&lineset->group->id);
        }
        if (lineset->linestyle) {
-               lineset->linestyle->id.us--;
+               id_us_min(&lineset->linestyle->id);
        }
        BLI_remlink(&config->linesets, lineset);
        MEM_freeN(lineset);
index 4d83f8cf916bbbc812fcf4a4cb5f4a211ac41f06..86d010f5f7c994cec9274db4ee506c0b30a546ce 100644 (file)
@@ -439,14 +439,15 @@ void IDP_FreeString(IDProperty *prop)
  * \{ */
 void IDP_LinkID(IDProperty *prop, ID *id)
 {
-       if (prop->data.pointer) ((ID *)prop->data.pointer)->us--;
+       if (prop->data.pointer)
+               id_us_min(((ID *)prop->data.pointer));
        prop->data.pointer = id;
        id_us_plus(id);
 }
 
 void IDP_UnlinkID(IDProperty *prop)
 {
-       ((ID *)prop->data.pointer)->us--;
+       id_us_min(((ID *)prop->data.pointer));
 }
 /** \} */
 
index ff305434b1b4ce2d1aed4213151ea45d170afd5f..9dabe6ba56b3de55edd5408bdac773b0b1c176a4 100644 (file)
@@ -552,8 +552,8 @@ void BKE_image_make_local(struct Image *ima)
                        if (tex->id.lib == NULL) {
                                if (tex->ima == ima) {
                                        tex->ima = ima_new;
-                                       ima_new->id.us++;
-                                       ima->id.us--;
+                                       id_us_plus(&ima_new->id);
+                                       id_us_min(&ima->id);
                                }
                        }
                        tex = tex->id.next;
@@ -563,8 +563,8 @@ void BKE_image_make_local(struct Image *ima)
                        if (brush->id.lib == NULL) {
                                if (brush->clone.image == ima) {
                                        brush->clone.image = ima_new;
-                                       ima_new->id.us++;
-                                       ima->id.us--;
+                                       id_us_plus(&ima_new->id);
+                                       id_us_min(&ima->id);
                                }
                        }
                        brush = brush->id.next;
@@ -744,7 +744,7 @@ Image *BKE_image_load_exists_ex(const char *filepath, bool *r_exists)
                                if ((BKE_image_has_anim(ima) == false) ||
                                    (ima->id.us == 0))
                                {
-                                       ima->id.us++;  /* officially should not, it doesn't link here! */
+                                       id_us_plus(&ima->id);  /* officially should not, it doesn't link here! */
                                        if (ima->ok == 0)
                                                ima->ok = IMA_OK;
                                        if (r_exists)
index 0c3fd48628f83cb94c2befd3a2b9b1dd1d452eed..8985dd372a61babc1da0221a2b0361d3e8419cd2 100644 (file)
@@ -71,6 +71,7 @@
 #include "BKE_action.h"
 #include "BKE_fcurve.h"
 #include "BKE_global.h"
+#include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_nla.h"
 #include "BKE_sequencer.h"
@@ -1429,7 +1430,7 @@ static void ipo_to_animato(ID *id, Ipo *ipo, char actname[], char constname[], S
        }
        
        /* if this IPO block doesn't have any users after this one, free... */
-       ipo->id.us--;
+       id_us_min(&ipo->id);
        if (ID_REAL_USERS(ipo) <= 0) {
                IpoCurve *icn;
                
@@ -1477,7 +1478,7 @@ static void action_to_animato(ID *id, bAction *act, ListBase *groups, ListBase *
                /* convert Action Channel's IPO data */
                if (achan->ipo) {
                        ipo_to_animato(id, achan->ipo, achan->name, NULL, NULL, groups, curves, drivers);
-                       achan->ipo->id.us--;
+                       id_us_min(&achan->ipo->id);
                        achan->ipo = NULL;
                }
                
@@ -1489,7 +1490,7 @@ static void action_to_animato(ID *id, bAction *act, ListBase *groups, ListBase *
                        /* convert Constraint Channel's IPO data */
                        if (conchan->ipo) {
                                ipo_to_animato(id, conchan->ipo, achan->name, conchan->name, NULL, groups, curves, drivers);
-                               conchan->ipo->id.us--;
+                               id_us_min(&conchan->ipo->id);
                                conchan->ipo = NULL;
                        }
                        
@@ -1718,7 +1719,7 @@ void do_versions_ipos_to_animato(Main *main)
                        if (ob->ipo) {
                                ipo_to_animdata(id, ob->ipo, NULL, NULL, NULL);
                                
-                               ob->ipo->id.us--;
+                               id_us_min(&ob->ipo->id);
                                ob->ipo = NULL;
                        }
                        
@@ -1726,7 +1727,7 @@ void do_versions_ipos_to_animato(Main *main)
                         * causing errors with evaluation in the new evaluation pipeline
                         */
                        if (ob->action) {
-                               ob->action->id.us--;
+                               id_us_min(&ob->action->id);
                                ob->action = NULL;
                        }
                        
@@ -1743,7 +1744,7 @@ void do_versions_ipos_to_animato(Main *main)
                                
                                /* only decrease usercount if this Action isn't now being used by AnimData */
                                if (ob->action != adt->action) {
-                                       ob->action->id.us--;
+                                       id_us_min(&ob->action->id);
                                        ob->action = NULL;
                                }
                        }
@@ -1751,7 +1752,7 @@ void do_versions_ipos_to_animato(Main *main)
                        /* IPO second... */
                        if (ob->ipo) {
                                ipo_to_animdata(id, ob->ipo, NULL, NULL, NULL);
-                               ob->ipo->id.us--;
+                               id_us_min(&ob->ipo->id);
                                ob->ipo = NULL;
 
                                {
@@ -1788,7 +1789,7 @@ void do_versions_ipos_to_animato(Main *main)
                                                 * so that drivers can be added properly...
                                                 */
                                                ipo_to_animdata(id, con->ipo, pchan->name, con->name, NULL);
-                                               con->ipo->id.us--;
+                                               id_us_min(&con->ipo->id);
                                                con->ipo = NULL;
                                        }
                                }
@@ -1808,7 +1809,7 @@ void do_versions_ipos_to_animato(Main *main)
                                 * so that drivers can be added properly...
                                 */
                                ipo_to_animdata(id, con->ipo, NULL, con->name, NULL);
-                               con->ipo->id.us--;
+                               id_us_min(&con->ipo->id);
                                con->ipo = NULL;
                        }
                         
@@ -1828,7 +1829,7 @@ void do_versions_ipos_to_animato(Main *main)
                                /* convert Constraint Channel's IPO data */
                                if (conchan->ipo) {
                                        ipo_to_animdata(id, conchan->ipo, NULL, conchan->name, NULL);
-                                       conchan->ipo->id.us--;
+                                       id_us_min(&conchan->ipo->id);
                                        conchan->ipo = NULL;
                                }
                                
@@ -1865,7 +1866,7 @@ void do_versions_ipos_to_animato(Main *main)
                        if (adt->action)
                                adt->action->idroot = key->ipo->blocktype;
                        
-                       key->ipo->id.us--;
+                       id_us_min(&key->ipo->id);
                        key->ipo = NULL;
                }
        }
@@ -1887,7 +1888,7 @@ void do_versions_ipos_to_animato(Main *main)
                        if (adt->action)
                                adt->action->idroot = ma->ipo->blocktype;
                        
-                       ma->ipo->id.us--;
+                       id_us_min(&ma->ipo->id);
                        ma->ipo = NULL;
                }
        }
@@ -1909,7 +1910,7 @@ void do_versions_ipos_to_animato(Main *main)
                        if (adt->action)
                                adt->action->idroot = wo->ipo->blocktype;
                        
-                       wo->ipo->id.us--;
+                       id_us_min(&wo->ipo->id);
                        wo->ipo = NULL;
                }
        }
@@ -1960,7 +1961,7 @@ void do_versions_ipos_to_animato(Main *main)
                                if (adt->action)
                                        adt->action->idroot = ID_SCE;  /* scene-rooted */
                                
-                               seq->ipo->id.us--;
+                               id_us_min(&seq->ipo->id);
                                seq->ipo = NULL;
                        }
                        SEQ_END
@@ -1985,7 +1986,7 @@ void do_versions_ipos_to_animato(Main *main)
                        if (adt->action)
                                adt->action->idroot = te->ipo->blocktype;
                        
-                       te->ipo->id.us--;
+                       id_us_min(&te->ipo->id);
                        te->ipo = NULL;
                }
        }
@@ -2007,7 +2008,7 @@ void do_versions_ipos_to_animato(Main *main)
                        if (adt->action)
                                adt->action->idroot = ca->ipo->blocktype;
                        
-                       ca->ipo->id.us--;
+                       id_us_min(&ca->ipo->id);
                        ca->ipo = NULL;
                }
        }
@@ -2029,7 +2030,7 @@ void do_versions_ipos_to_animato(Main *main)
                        if (adt->action)
                                adt->action->idroot = la->ipo->blocktype;
                        
-                       la->ipo->id.us--;
+                       id_us_min(&la->ipo->id);
                        la->ipo = NULL;
                }
        }
@@ -2051,7 +2052,7 @@ void do_versions_ipos_to_animato(Main *main)
                        if (adt->action)
                                adt->action->idroot = cu->ipo->blocktype;
                        
-                       cu->ipo->id.us--;
+                       id_us_min(&cu->ipo->id);
                        cu->ipo = NULL;
                }
        }
index 8e350896eb885156d9ad66d2e8203179cf72a8f9..7fcbd9cafb7613aa6ec5ed2d9c1d2dd5e7ec380a 100644 (file)
@@ -209,8 +209,8 @@ void BKE_lamp_make_local(Lamp *la)
                                
                                if (ob->id.lib == NULL) {
                                        ob->data = la_new;
-                                       la_new->id.us++;
-                                       la->id.us--;
+                                       id_us_plus(&la_new->id);
+                                       id_us_min(&la->id);
                                }
                        }
                        ob = ob->id.next;
@@ -225,8 +225,10 @@ void BKE_lamp_free(Lamp *la)
 
        for (a = 0; a < MAX_MTEX; a++) {
                mtex = la->mtex[a];
-               if (mtex && mtex->tex) mtex->tex->id.us--;
-               if (mtex) MEM_freeN(mtex);
+               if (mtex && mtex->tex)
+                       id_us_min(&mtex->tex->id);
+               if (mtex)
+                       MEM_freeN(mtex);
        }
        
        BKE_animdata_free((ID *)la);
index 0e5228a6db46399e3df2b01e1eb51ee4633f8050..1992eabafec77993f7605e76430f72740738757d 100644 (file)
@@ -360,8 +360,8 @@ void BKE_lattice_make_local(Lattice *lt)
                        if (ob->data == lt) {
                                if (ob->id.lib == NULL) {
                                        ob->data = lt_new;
-                                       lt_new->id.us++;
-                                       lt->id.us--;
+                                       id_us_plus(&lt_new->id);
+                                       id_us_min(&lt->id);
                                }
                        }
                }
index c618795eb52cc50a7b28c408eaa1bc9b18d17d26..90cd950a78dc787be6c81ba25820c3239a5c3a62 100644 (file)
@@ -185,6 +185,7 @@ void id_us_min(ID *id)
 {
        if (id) {
                if (id->us < 2 && (id->flag & LIB_FAKEUSER)) {
+                       printf("ID user decrement error: %s\n", id->name);
                        id->us = 1;
                }
                else if (id->us <= 0) {
index 93d2b549feeb2604852a80442d5f994d29fb96f6..5a1dfc0404592d1e6d0a1678e6391e907b963b33 100644 (file)
@@ -134,8 +134,10 @@ void BKE_linestyle_free(FreestyleLineStyle *linestyle)
 
        for (a = 0; a < MAX_MTEX; a++) {
                mtex = linestyle->mtex[a];
-               if (mtex && mtex->tex) mtex->tex->id.us--;
-               if (mtex) MEM_freeN(mtex);
+               if (mtex && mtex->tex)
+                       id_us_min(&mtex->tex->id);
+               if (mtex)
+                       MEM_freeN(mtex);
        }
        if (linestyle->nodetree) {
                ntreeFreeTree(linestyle->nodetree);
@@ -384,7 +386,7 @@ LineStyleModifier *BKE_linestyle_color_modifier_copy(FreestyleLineStyle *linesty
                        LineStyleColorModifier_DistanceFromObject *p = (LineStyleColorModifier_DistanceFromObject *)m;
                        LineStyleColorModifier_DistanceFromObject *q = (LineStyleColorModifier_DistanceFromObject *)new_m;
                        if (p->target)
-                               p->target->id.us++;
+                               id_us_plus(&p->target->id);
                        q->target = p->target;
                        q->color_ramp = MEM_dupallocN(p->color_ramp);
                        q->range_min = p->range_min;
@@ -622,7 +624,7 @@ LineStyleModifier *BKE_linestyle_alpha_modifier_copy(FreestyleLineStyle *linesty
                        LineStyleAlphaModifier_DistanceFromObject *p = (LineStyleAlphaModifier_DistanceFromObject *)m;
                        LineStyleAlphaModifier_DistanceFromObject *q = (LineStyleAlphaModifier_DistanceFromObject *)new_m;
                        if (p->target)
-                               p->target->id.us++;
+                               id_us_plus(&p->target->id);
                        q->target = p->target;
                        q->curve = curvemapping_copy(p->curve);
                        q->flags = p->flags;
@@ -897,7 +899,7 @@ LineStyleModifier *BKE_linestyle_thickness_modifier_copy(FreestyleLineStyle *lin
                        LineStyleThicknessModifier_DistanceFromObject *p = (LineStyleThicknessModifier_DistanceFromObject *)m;
                        LineStyleThicknessModifier_DistanceFromObject *q = (LineStyleThicknessModifier_DistanceFromObject *)new_m;
                        if (p->target)
-                               p->target->id.us++;
+                               id_us_plus(&p->target->id);
                        q->target = p->target;
                        q->curve = curvemapping_copy(p->curve);
                        q->flags = p->flags;
index 141597e859c41710a7369d724ba22da37745bd1b..b79c72a425156aa92366ccda0a54b01ca393c8f9 100644 (file)
@@ -845,7 +845,7 @@ Mask *BKE_mask_copy_nolib(Mask *mask)
        /* enable fake user by default */
        if (!(mask_new->id.flag & LIB_FAKEUSER)) {
                mask_new->id.flag |= LIB_FAKEUSER;
-               mask_new->id.us++;
+               id_us_plus(&mask_new->id);
        }
 
        return mask_new;
@@ -864,7 +864,7 @@ Mask *BKE_mask_copy(Mask *mask)
        /* enable fake user by default */
        if (!(mask_new->id.flag & LIB_FAKEUSER)) {
                mask_new->id.flag |= LIB_FAKEUSER;
-               mask_new->id.us++;
+               id_us_plus(&mask_new->id);
        }
 
        if (mask->id.lib) {
index a69b5fd87b536896a54207a8006425156242d21f..ba81f68ff23ce970775328f8a7fef38291e6ffad 100644 (file)
@@ -95,8 +95,10 @@ void BKE_material_free_ex(Material *ma, bool do_id_user)
        
        for (a = 0; a < MAX_MTEX; a++) {
                mtex = ma->mtex[a];
-               if (do_id_user && mtex && mtex->tex) mtex->tex->id.us--;
-               if (mtex) MEM_freeN(mtex);
+               if (do_id_user && mtex && mtex->tex)
+                       id_us_min(&mtex->tex->id);
+               if (mtex)
+                       MEM_freeN(mtex);
        }
        
        if (ma->ramp_col) MEM_freeN(ma->ramp_col);
@@ -403,8 +405,8 @@ void BKE_material_make_local(Material *ma)
                                        if (ob->mat[a] == ma) {
                                                if (ob->id.lib == NULL) {
                                                        ob->mat[a] = ma_new;
-                                                       ma_new->id.us++;
-                                                       ma->id.us--;
+                                                       id_us_plus(&ma_new->id);
+                                                       id_us_min(&ma->id);
                                                }
                                        }
                                }
@@ -419,8 +421,8 @@ void BKE_material_make_local(Material *ma)
                                        if (me->mat[a] == ma) {
                                                if (me->id.lib == NULL) {
                                                        me->mat[a] = ma_new;
-                                                       ma_new->id.us++;
-                                                       ma->id.us--;
+                                                       id_us_plus(&ma_new->id);
+                                                       id_us_min(&ma->id);
                                                }
                                        }
                                }
@@ -435,8 +437,8 @@ void BKE_material_make_local(Material *ma)
                                        if (cu->mat[a] == ma) {
                                                if (cu->id.lib == NULL) {
                                                        cu->mat[a] = ma_new;
-                                                       ma_new->id.us++;
-                                                       ma->id.us--;
+                                                       id_us_plus(&ma_new->id);
+                                                       id_us_min(&ma->id);
                                                }
                                        }
                                }
@@ -451,8 +453,8 @@ void BKE_material_make_local(Material *ma)
                                        if (mb->mat[a] == ma) {
                                                if (mb->id.lib == NULL) {
                                                        mb->mat[a] = ma_new;
-                                                       ma_new->id.us++;
-                                                       ma->id.us--;
+                                                       id_us_plus(&ma_new->id);
+                                                       id_us_min(&ma->id);
                                                }
                                        }
                                }
@@ -840,11 +842,12 @@ void assign_material_id(ID *id, Material *ma, short act)
 
        /* in data */
        mao = (*matarar)[act - 1];
-       if (mao) mao->id.us--;
+       if (mao)
+               id_us_min(&mao->id);
        (*matarar)[act - 1] = ma;
 
        if (ma)
-               id_us_plus((ID *)ma);
+               id_us_plus(&ma->id);
 
        test_object_materials(G.main, id);
 }
@@ -918,17 +921,19 @@ void assign_material(Object *ob, Material *ma, short act, int assign_type)
        ob->matbits[act - 1] = bit;
        if (bit == 1) {   /* in object */
                mao = ob->mat[act - 1];
-               if (mao) mao->id.us--;
+               if (mao)
+                       id_us_min(&mao->id);
                ob->mat[act - 1] = ma;
        }
        else {  /* in data */
                mao = (*matarar)[act - 1];
-               if (mao) mao->id.us--;
+               if (mao)
+                       id_us_min(&mao->id);
                (*matarar)[act - 1] = ma;
        }
 
        if (ma)
-               id_us_plus((ID *)ma);
+               id_us_plus(&ma->id);
        test_object_materials(G.main, ob->data);
 }
 
@@ -1306,7 +1311,8 @@ bool object_remove_material_slot(Object *ob)
        
        /* we delete the actcol */
        mao = (*matarar)[ob->actcol - 1];
-       if (mao) mao->id.us--;
+       if (mao)
+               id_us_min(&mao->id);
        
        for (a = ob->actcol; a < ob->totcol; a++)
                (*matarar)[a - 1] = (*matarar)[a];
@@ -1325,7 +1331,8 @@ bool object_remove_material_slot(Object *ob)
                        
                        /* WATCH IT: do not use actcol from ob or from obt (can become zero) */
                        mao = obt->mat[actcol - 1];
-                       if (mao) mao->id.us--;
+                       if (mao)
+                               id_us_min(&mao->id);
                
                        for (a = actcol; a < obt->totcol; a++) {
                                obt->mat[a - 1] = obt->mat[a];
@@ -1804,8 +1811,10 @@ void paste_matcopybuf(Material *ma)
        if (ma->ramp_spec) MEM_freeN(ma->ramp_spec);
        for (a = 0; a < MAX_MTEX; a++) {
                mtex = ma->mtex[a];
-               if (mtex && mtex->tex) mtex->tex->id.us--;
-               if (mtex) MEM_freeN(mtex);
+               if (mtex && mtex->tex)
+                       id_us_min(&mtex->tex->id);
+               if (mtex)
+                       MEM_freeN(mtex);
        }
 
        if (ma->nodetree) {
index bd9fd33158467ea56099e550699e8a286f2f2422..1d409e9ffe82ef65790d0efffa38f129c73d6ae0 100644 (file)
@@ -71,7 +71,8 @@ void BKE_mball_unlink(MetaBall *mb)
        int a;
        
        for (a = 0; a < mb->totcol; a++) {
-               if (mb->mat[a]) mb->mat[a]->id.us--;
+               if (mb->mat[a])
+                       id_us_min(&mb->mat[a]->id);
                mb->mat[a] = NULL;
        }
 }
@@ -186,8 +187,8 @@ void BKE_mball_make_local(MetaBall *mb)
                        if (ob->data == mb) {
                                if (ob->id.lib == NULL) {
                                        ob->data = mb_new;
-                                       mb_new->id.us++;
-                                       mb->id.us--;
+                                       id_us_plus(&mb_new->id);
+                                       id_us_min(&mb->id);
                                }
                        }
                }
index 318040db2be382f0b2629f741bea04ae4b5f928b..12559e276d31b30ce134862b7b6c46ca0d38cee4 100644 (file)
@@ -438,13 +438,14 @@ void BKE_mesh_unlink(Mesh *me)
 
        if (me->mat) {
                for (a = 0; a < me->totcol; a++) {
-                       if (me->mat[a]) me->mat[a]->id.us--;
+                       if (me->mat[a])
+                               id_us_min(&me->mat[a]->id);
                        me->mat[a] = NULL;
                }
        }
 
        if (me->key) {
-               me->key->id.us--;
+               id_us_min(&me->key->id);
        }
        me->key = NULL;
        
@@ -1031,7 +1032,7 @@ void BKE_mesh_assign_object(Object *ob, Mesh *me)
        if (ob->type == OB_MESH) {
                old = ob->data;
                if (old)
-                       old->id.us--;
+                       id_us_min(&old->id);
                ob->data = me;
                id_us_plus((ID *)me);
        }
@@ -1728,7 +1729,7 @@ void BKE_mesh_to_curve(Scene *scene, Object *ob)
 
                cu->nurb = nurblist;
 
-               ((Mesh *)ob->data)->id.us--;
+               id_us_min(&((Mesh *)ob->data)->id);
                ob->data = cu;
                ob->type = OB_CURVE;
 
@@ -2346,7 +2347,7 @@ Mesh *BKE_mesh_new_from_object(
                        /* copies object and modifiers (but not the data) */
                        tmpobj = BKE_object_copy_ex(bmain, ob, true);
                        tmpcu = (Curve *)tmpobj->data;
-                       tmpcu->id.us--;
+                       id_us_min(&tmpcu->id);
 
                        /* Copy cached display list, it might be needed by the stack evaluation.
                         * Ideally stack should be able to use render-time display list, but doing
@@ -2416,7 +2417,7 @@ Mesh *BKE_mesh_new_from_object(
 
                        tmpmesh = BKE_mesh_add(bmain, "Mesh");
                        /* BKE_mesh_add gives us a user count we don't need */
-                       tmpmesh->id.us--;
+                       id_us_min(&tmpmesh->id);
 
                        if (render) {
                                ListBase disp = {NULL, NULL};
@@ -2471,7 +2472,7 @@ Mesh *BKE_mesh_new_from_object(
                        }
 
                        /* BKE_mesh_add/copy gives us a user count we don't need */
-                       tmpmesh->id.us--;
+                       id_us_min(&tmpmesh->id);
 
                        break;
                default:
@@ -2494,7 +2495,7 @@ Mesh *BKE_mesh_new_from_object(
                                        tmpmesh->mat[i] = ob->matbits[i] ? ob->mat[i] : tmpcu->mat[i];
 
                                        if (tmpmesh->mat[i]) {
-                                               tmpmesh->mat[i]->id.us++;
+                                               id_us_plus(&tmpmesh->mat[i]->id);
                                        }
                                }
                        }
@@ -2511,7 +2512,7 @@ Mesh *BKE_mesh_new_from_object(
                                for (i = tmpmb->totcol; i-- > 0; ) {
                                        tmpmesh->mat[i] = tmpmb->mat[i]; /* CRASH HERE ??? */
                                        if (tmpmesh->mat[i]) {
-                                               tmpmb->mat[i]->id.us++;
+                                               id_us_plus(&tmpmb->mat[i]->id);
                                        }
                                }
                        }
@@ -2531,7 +2532,7 @@ Mesh *BKE_mesh_new_from_object(
                                                tmpmesh->mat[i] = ob->matbits[i] ? ob->mat[i] : origmesh->mat[i];
 
                                                if (tmpmesh->mat[i]) {
-                                                       tmpmesh->mat[i]->id.us++;
+                                                       id_us_plus(&tmpmesh->mat[i]->id);
                                                }
                                        }
                                }
index 432ae32f02b8093ee27ddb812152c0dcff0f3056..0828f4e9e0e331023cdde5c506ba349870b54472 100644 (file)
@@ -649,7 +649,7 @@ MovieClip *BKE_movieclip_file_add_exists_ex(Main *bmain, const char *filepath, b
                BLI_path_abs(strtest, ID_BLEND_PATH(bmain, &clip->id));
 
                if (BLI_path_cmp(strtest, str) == 0) {
-                       clip->id.us++;  /* officially should not, it doesn't link here! */
+                       id_us_plus(&clip->id);  /* officially should not, it doesn't link here! */
                        if (r_exists)
                                *r_exists = true;
                        return clip;
index 65245477c7f22c1357f29ff1fd3f4378bce20059..0527df67033da163e71f9471ba1f442dcf65e07a 100644 (file)
@@ -1935,7 +1935,8 @@ void BKE_nla_tweakmode_exit(AnimData *adt)
         *      - editing-flag for this AnimData block should also get turned off
         *      - clear pointer to active strip
         */
-       if (adt->action) adt->action->id.us--;
+       if (adt->action)
+               id_us_min(&adt->action->id);
        adt->action = adt->tmpact;
        adt->tmpact = NULL;
        adt->act_track = NULL;
index 68d9609e0697c44a670f0f472099ef07fd618e56..70f2f9d26e085b6249325eef1f19db5ec6a2b040 100644 (file)
@@ -2017,8 +2017,8 @@ void ntreeMakeLocal(bNodeTree *ntree)
                                if (node->id == (ID *)ntree) {
                                        if (owner_id->lib == NULL) {
                                                node->id = (ID *)newtree;
-                                               newtree->id.us++;
-                                               ntree->id.us--;
+                                               id_us_plus(&newtree->id);
+                                               id_us_min(&ntree->id);
                                        }
                                }
                        }
@@ -2106,8 +2106,10 @@ bNodeTree *ntreeLocalize(bNodeTree *ntree)
                        adt->action = ladt->action = action_backup;
                        adt->tmpact = ladt->tmpact = tmpact_backup;
 
-                       if (action_backup) action_backup->id.us++;
-                       if (tmpact_backup) tmpact_backup->id.us++;
+                       if (action_backup)
+                               id_us_plus(&action_backup->id);
+                       if (tmpact_backup)
+                               id_us_plus(&tmpact_backup->id);
 
                }
                /* end animdata uglyness */
index 456791e99fc29f90b56a77eb3c26b93c22ac1195..1e345605ec2c788ec6bd07d477299adec2b2aa8f 100644 (file)
@@ -40,6 +40,7 @@
 #include "DNA_armature_types.h"
 #include "DNA_camera_types.h"
 #include "DNA_constraint_types.h"
+#include "DNA_gpencil_types.h"
 #include "DNA_group_types.h"
 #include "DNA_key_types.h"
 #include "DNA_lamp_types.h"
@@ -389,7 +390,7 @@ void BKE_object_free_ex(Object *ob, bool do_id_user)
        /* disconnect specific data, but not for lib data (might be indirect data, can get relinked) */
        if (ob->data) {
                ID *id = ob->data;
-               id->us--;
+               id_us_min(id);
                if (id->us == 0 && id->lib == NULL) {
                        switch (ob->type) {
                                case OB_MESH:
@@ -408,7 +409,8 @@ void BKE_object_free_ex(Object *ob, bool do_id_user)
 
        if (ob->mat) {
                for (a = 0; a < ob->totcol; a++) {
-                       if (ob->mat[a]) ob->mat[a]->id.us--;
+                       if (ob->mat[a])
+                               id_us_min(&ob->mat[a]->id);
                }
                MEM_freeN(ob->mat);
        }
@@ -420,8 +422,10 @@ void BKE_object_free_ex(Object *ob, bool do_id_user)
        if (ob->bb) MEM_freeN(ob->bb); 
        ob->bb = NULL;
        if (ob->adt) BKE_animdata_free((ID *)ob);
-       if (ob->poselib) ob->poselib->id.us--;
-       if (ob->gpd) ((ID *)ob->gpd)->us--;
+       if (ob->poselib)
+               id_us_min(&ob->poselib->id);
+       if (ob->gpd)
+               id_us_min(&ob->gpd->id);
        if (ob->defbase.first)
                BLI_freelistN(&ob->defbase);
        if (ob->pose)
@@ -1656,8 +1660,8 @@ void BKE_object_make_local(Object *ob)
                                        while (base) {
                                                if (base->object == ob) {
                                                        base->object = ob_new;
-                                                       ob_new->id.us++;
-                                                       ob->id.us--;
+                                                       id_us_plus(&ob_new->id);
+                                                       id_us_min(&ob->id);
                                                }
                                                base = base->next;
                                        }
index 29bd27de2e693b0da802493ea38b10c1775a5d82..ae18c6f4aade86534f0e2442b6db9892b464dd70 100644 (file)
@@ -395,8 +395,10 @@ void BKE_particlesettings_free(ParticleSettings *part)
 
        for (a = 0; a < MAX_MTEX; a++) {
                mtex = part->mtex[a];
-               if (mtex && mtex->tex) mtex->tex->id.us--;
-               if (mtex) MEM_freeN(mtex);
+               if (mtex && mtex->tex)
+                       id_us_min(&mtex->tex->id);
+               if (mtex)
+                       MEM_freeN(mtex);
        }
 }
 
@@ -567,7 +569,7 @@ void psys_free(Object *ob, ParticleSystem *psys)
                        ob->transflag &= ~OB_DUPLIPARTS;
 
                if (psys->part) {
-                       psys->part->id.us--;
+                       id_us_min(&psys->part->id);
                        psys->part = NULL;
                }
 
@@ -3315,8 +3317,8 @@ void BKE_particlesettings_make_local(ParticleSettings *part)
                        for (psys = ob->particlesystem.first; psys; psys = psys->next) {
                                if (psys->part == part && ob->id.lib == 0) {
                                        psys->part = part_new;
-                                       part_new->id.us++;
-                                       part->id.us--;
+                                       id_us_plus(&part_new->id);
+                                       id_us_min(&part->id);
                                }
                        }
                }
index 6fe92a4ac2320340c769b754f6c88050f1ed4907..82a040f4ca0bf53f2bef6101e814447e0a540b05 100644 (file)
@@ -368,7 +368,7 @@ void BKE_scene_free(Scene *sce)
 
        base = sce->base.first;
        while (base) {
-               base->object->id.us--;
+               id_us_min(&base->object->id);
                base = base->next;
        }
        /* do not free objects! */
@@ -378,7 +378,7 @@ void BKE_scene_free(Scene *sce)
                /* since the grease pencil data is freed before the scene.
                 * since grease pencil data is not (yet?), shared between objects
                 * its probably safe not to do this, some save and reload will free this. */
-               sce->gpd->id.us--;
+               id_us_min(&sce->gpd->id);
 #endif
                sce->gpd = NULL;
        }
index 4a24b149c34a4e6f3b3b51d087a259be2d93a23f..45d33e51e18330a8a2288bd44d81cdae34d460e4 100644 (file)
@@ -198,7 +198,7 @@ static void BKE_sequence_free_ex(Scene *scene, Sequence *seq, const bool do_cach
        }
 
        if (seq->sound) {
-               ((ID *)seq->sound)->us--; 
+               id_us_min(((ID *)seq->sound));
        }
 
        if (seq->stereo3d_format) {
index 7e7cc8745fde1a7465a1d3ebf0e64ef2eeab9b8e..69f4dbcd5028bb8490facc4ffb5d1ebe30431654 100644 (file)
@@ -106,7 +106,7 @@ bSound *BKE_sound_new_file_exists_ex(struct Main *bmain, const char *filepath, b
                BLI_path_abs(strtest, ID_BLEND_PATH(bmain, &sound->id));
 
                if (BLI_path_cmp(strtest, str) == 0) {
-                       sound->id.us++;  /* officially should not, it doesn't link here! */
+                       id_us_plus(&sound->id);  /* officially should not, it doesn't link here! */
                        if (r_exists)
                                *r_exists = true;
                        return sound;
index 30296c7813c0f1d963349cff9af44f375de4bf4a..3b5b8ce3f9a6d19da6c7a91058d41836ac0bb7f5 100644 (file)
@@ -72,7 +72,7 @@ Speaker *BKE_speaker_copy(Speaker *spk)
 
        spkn = BKE_libblock_copy(&spk->id);
        if (spkn->sound)
-               spkn->sound->id.us++;
+               id_us_plus(&spkn->sound->id);
 
        if (spk->id.lib) {
                BKE_id_lib_local_paths(G.main, spk->id.lib, &spkn->id);
@@ -123,8 +123,8 @@ void BKE_speaker_make_local(Speaker *spk)
 
                                if (ob->id.lib == NULL) {
                                        ob->data = spk_new;
-                                       spk_new->id.us++;
-                                       spk->id.us--;
+                                       id_us_plus(&spk_new->id);
+                                       id_us_min(&spk->id);
                                }
                        }
                        ob = ob->id.next;
@@ -135,7 +135,7 @@ void BKE_speaker_make_local(Speaker *spk)
 void BKE_speaker_free(Speaker *spk)
 {
        if (spk->sound)
-               spk->sound->id.us--;
+               id_us_min(&spk->sound->id);
 
        BKE_animdata_free((ID *)spk);
 }
index 463ca250ad51bcfabd92a6655ae5588dc8edb92c..d353042b7115518d34a42d6a2e9299d3ce01087d 100644 (file)
@@ -1009,8 +1009,8 @@ void BKE_texture_make_local(Tex *tex)
                                if (ma->mtex[a] && ma->mtex[a]->tex == tex) {
                                        if (ma->id.lib == NULL) {
                                                ma->mtex[a]->tex = tex_new;
-                                               tex_new->id.us++;
-                                               tex->id.us--;
+                                               id_us_plus(&tex_new->id);
+                                               id_us_min(&tex->id);
                                        }
                                }
                        }
@@ -1022,8 +1022,8 @@ void BKE_texture_make_local(Tex *tex)
                                if (la->mtex[a] && la->mtex[a]->tex == tex) {
                                        if (la->id.lib == NULL) {
                                                la->mtex[a]->tex = tex_new;
-                                               tex_new->id.us++;
-                                               tex->id.us--;
+                                               id_us_plus(&tex_new->id);
+                                               id_us_min(&tex->id);
                                        }
                                }
                        }
@@ -1035,8 +1035,8 @@ void BKE_texture_make_local(Tex *tex)
                                if (wrld->mtex[a] && wrld->mtex[a]->tex == tex) {
                                        if (wrld->id.lib == NULL) {
                                                wrld->mtex[a]->tex = tex_new;
-                                               tex_new->id.us++;
-                                               tex->id.us--;
+                                               id_us_plus(&tex_new->id);
+                                               id_us_min(&tex->id);
                                        }
                                }
                        }
@@ -1047,15 +1047,15 @@ void BKE_texture_make_local(Tex *tex)
                        if (br->mtex.tex == tex) {
                                if (br->id.lib == NULL) {
                                        br->mtex.tex = tex_new;
-                                       tex_new->id.us++;
-                                       tex->id.us--;
+                                       id_us_plus(&tex_new->id);
+                                       id_us_min(&tex->id);
                                }
                        }
                        if (br->mask_mtex.tex == tex) {
                                if (br->id.lib == NULL) {
                                        br->mask_mtex.tex = tex_new;
-                                       tex_new->id.us++;
-                                       tex->id.us--;
+                                       id_us_plus(&tex_new->id);
+                                       id_us_min(&tex->id);
                                }
                        }
                        br = br->id.next;
@@ -1066,8 +1066,8 @@ void BKE_texture_make_local(Tex *tex)
                                if (pa->mtex[a] && pa->mtex[a]->tex == tex) {
                                        if (pa->id.lib == NULL) {
                                                pa->mtex[a]->tex = tex_new;
-                                               tex_new->id.us++;
-                                               tex->id.us--;
+                                               id_us_plus(&tex_new->id);
+                                               id_us_min(&tex->id);
                                        }
                                }
                        }
@@ -1079,8 +1079,8 @@ void BKE_texture_make_local(Tex *tex)
                                if (ls->mtex[a] && ls->mtex[a]->tex == tex) {
                                        if (ls->id.lib == NULL) {
                                                ls->mtex[a]->tex = tex_new;
-                                               tex_new->id.us++;
-                                               tex->id.us--;
+                                               id_us_plus(&tex_new->id);
+                                               id_us_min(&tex->id);
                                        }
                                }
                        }
index 88c98b6d9d83ff03ae985f01701736985f98f395..17a2e7f14fd10e20e5d5562a85ffe088f7c648e9 100644 (file)
@@ -59,8 +59,10 @@ void BKE_world_free_ex(World *wrld, bool do_id_user)
        
        for (a = 0; a < MAX_MTEX; a++) {
                mtex = wrld->mtex[a];
-               if (do_id_user && mtex && mtex->tex) mtex->tex->id.us--;
-               if (mtex) MEM_freeN(mtex);
+               if (do_id_user && mtex && mtex->tex)
+                       id_us_min(&mtex->tex->id);
+               if (mtex)
+                       MEM_freeN(mtex);
        }
        BKE_previewimg_free(&wrld->preview);
 
@@ -220,8 +222,8 @@ void BKE_world_make_local(World *wrld)
                        if (sce->world == wrld) {
                                if (sce->id.lib == NULL) {
                                        sce->world = wrld_new;
-                                       wrld_new->id.us++;
-                                       wrld->id.us--;
+                                       id_us_plus(&wrld_new->id);
+                                       id_us_min(&wrld->id);
                                }
                        }
                }
index 674a79f0fe74ec092258d8ee87649bfcc692213d..498e65790f3ac1bef1d7a3dd5617fc0f9507cba1 100644 (file)
@@ -388,7 +388,7 @@ Object *DocumentImporter::create_camera_object(COLLADAFW::InstanceCamera *camera
        Camera *cam = uid_camera_map[cam_uid];
        Camera *old_cam = (Camera *)ob->data;
        ob->data = cam;
-       old_cam->id.us--;
+       id_us_min(&old_cam->id);
        if (old_cam->id.us == 0)
                BKE_libblock_free(G.main, old_cam);
        return ob;
@@ -406,7 +406,7 @@ Object *DocumentImporter::create_lamp_object(COLLADAFW::InstanceLight *lamp, Sce
        Lamp *la = uid_lamp_map[lamp_uid];
        Lamp *old_lamp = (Lamp *)ob->data;
        ob->data = la;
-       old_lamp->id.us--;
+       id_us_min(&old_lamp->id);
        if (old_lamp->id.us == 0)
                BKE_libblock_free(G.main, old_lamp);
        return ob;
index 2adbdd27cdfa9381d1b7ecb4b2117c31aaf0c129..64df42fc823e08ef00de6c030cbf8fcec60994dd 100644 (file)
@@ -1176,7 +1176,7 @@ bool MeshImporter::write_geometry(const COLLADAFW::Geometry *geom)
        
        const std::string& str_geom_id = mesh->getName().size() ? mesh->getName() : mesh->getOriginalId();
        Mesh *me = BKE_mesh_add(G.main, (char *)str_geom_id.c_str());
-       me->id.us--; // is already 1 here, but will be set later in BKE_mesh_assign_object
+       id_us_min(&me->id); // is already 1 here, but will be set later in BKE_mesh_assign_object
 
        // store the Mesh pointer to link it later with an Object
        // mesh_geom_map needed to map mesh to its geometry name (for shape key naming)
index f7dab0c093598158df444651c3bb66ac67c876f0..5a47cc148d26447104aa90b7742622b54e5a0405 100644 (file)
@@ -49,6 +49,7 @@
 #include "BKE_fcurve.h"
 #include "BKE_global.h"
 #include "BKE_key.h"
+#include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_report.h"
 #include "BKE_animsys.h"
@@ -1298,7 +1299,7 @@ static int separate_exec(bContext *C, wmOperator *op)
        newob = newbase->object;
        newcu = newob->data = BKE_curve_copy(oldcu);
        newcu->editnurb = NULL;
-       oldcu->id.us--; /* because new curve is a copy: reduce user count */
+       id_us_min(&oldcu->id); /* because new curve is a copy: reduce user count */
 
        /* 3. put new object in editmode, clear it and set separated nurbs */
        make_editNurb(newob);
index ea6b6154be8ec0cf365d64b0137d4fc1828a78b4..1eee5d04c56c561b3c0f6ca5ef6a9bd46786b2a3 100644 (file)
@@ -51,6 +51,7 @@
 #include "BKE_curve.h"
 #include "BKE_depsgraph.h"
 #include "BKE_font.h"
+#include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_object.h"
 #include "BKE_report.h"
@@ -538,7 +539,7 @@ static void txt_add_object(bContext *C, TextLine *firstline, int totline, const
 
        cu = obedit->data;
        cu->vfont = BKE_vfont_builtin_get();
-       cu->vfont->id.us++;
+       id_us_plus(&cu->vfont->id);
 
        for (tmp = firstline, a = 0; nbytes < MAXTEXT && a < totline; tmp = tmp->next, a++) {
                size_t nchars_line, nbytes_line;
@@ -1727,7 +1728,7 @@ static int font_open_exec(bContext *C, wmOperator *op)
        if (pprop->prop) {
                /* when creating new ID blocks, use is already 1, but RNA
                 * pointer se also increases user, so this compensates it */
-               font->id.us--;
+               id_us_min(&font->id);
        
                RNA_id_pointer_create(&font->id, &idptr);
                RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr);
index 2491685161c0e2f6fd29fe935fa63b784990e54f..dee003135a2352c5614fe1b60766d4126d58e30b 100644 (file)
@@ -513,11 +513,13 @@ int join_mesh_exec(bContext *C, wmOperator *op)
        /* old material array */
        for (a = 1; a <= ob->totcol; a++) {
                ma = ob->mat[a - 1];
-               if (ma) ma->id.us--;
+               if (ma)
+                       id_us_min(&ma->id);
        }
        for (a = 1; a <= me->totcol; a++) {
                ma = me->mat[a - 1];
-               if (ma) ma->id.us--;
+               if (ma)
+                       id_us_min(&ma->id);
        }
        if (ob->mat) MEM_freeN(ob->mat);
        if (ob->matbits) MEM_freeN(ob->matbits);
index 269700c3aef73b4ea846d2c7206c121109371955..2cead58300dfef837e95cac34b11ed7fd25eadca 100644 (file)
@@ -1587,7 +1587,7 @@ static int convert_exec(bContext *C, wmOperator *op)
 
                                /* decrement original mesh's usage count  */
                                me = newob->data;
-                               me->id.us--;
+                               id_us_min(&me->id);
 
                                /* make a new copy of the mesh */
                                newob->data = BKE_mesh_copy(me);
@@ -1612,7 +1612,7 @@ static int convert_exec(bContext *C, wmOperator *op)
 
                                /* decrement original mesh's usage count  */
                                me = newob->data;
-                               me->id.us--;
+                               id_us_min(&me->id);
 
                                /* make a new copy of the mesh */
                                newob->data = BKE_mesh_copy(me);
@@ -1643,7 +1643,7 @@ static int convert_exec(bContext *C, wmOperator *op)
                                newob = basen->object;
 
                                /* decrement original curve's usage count  */
-                               ((Curve *)newob->data)->id.us--;
+                               id_us_min(&((Curve *)newob->data)->id);
 
                                /* make a new copy of the curve */
                                newob->data = BKE_curve_copy(ob->data);
@@ -1664,19 +1664,19 @@ static int convert_exec(bContext *C, wmOperator *op)
                        cu->type = OB_CURVE;
 
                        if (cu->vfont) {
-                               cu->vfont->id.us--;
+                               id_us_min(&cu->vfont->id);
                                cu->vfont = NULL;
                        }
                        if (cu->vfontb) {
-                               cu->vfontb->id.us--;
+                               id_us_min(&cu->vfontb->id);
                                cu->vfontb = NULL;
                        }
                        if (cu->vfonti) {
-                               cu->vfonti->id.us--;
+                               id_us_min(&cu->vfonti->id);
                                cu->vfonti = NULL;
                        }
                        if (cu->vfontbi) {
-                               cu->vfontbi->id.us--;
+                               id_us_min(&cu->vfontbi->id);
                                cu->vfontbi = NULL;
                        }
 
@@ -1714,7 +1714,7 @@ static int convert_exec(bContext *C, wmOperator *op)
                                        newob = basen->object;
 
                                        /* decrement original curve's usage count  */
-                                       ((Curve *)newob->data)->id.us--;
+                                       id_us_min(&((Curve *)newob->data)->id);
 
                                        /* make a new copy of the curve */
                                        newob->data = BKE_curve_copy(ob->data);
@@ -1749,7 +1749,7 @@ static int convert_exec(bContext *C, wmOperator *op)
                                newob = basen->object;
 
                                mb = newob->data;
-                               mb->id.us--;
+                               id_us_min(&mb->id);
 
                                newob->data = BKE_mesh_add(bmain, "Mesh");
                                newob->type = OB_MESH;
@@ -1915,7 +1915,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base
                                        ID_NEW_US(obn->mat[a])
                                        else
                                                obn->mat[a] = BKE_material_copy(obn->mat[a]);
-                                       id->us--;
+                                       id_us_min(id);
 
                                        if (dupflag & USER_DUP_ACT) {
                                                BKE_animdata_copy_id_action(&obn->mat[a]->id);
@@ -1936,7 +1936,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base
                                                BKE_animdata_copy_id_action(&psys->part->id);
                                        }
 
-                                       id->us--;
+                                       id_us_min(id);
                                }
                        }
                }
@@ -1952,7 +1952,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base
                                                obn->data = BKE_mesh_copy(obn->data);
                                                didit = 1;
                                        }
-                                       id->us--;
+                                       id_us_min(id);
                                }
                                break;
                        case OB_CURVE:
@@ -1962,7 +1962,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base
                                                obn->data = BKE_curve_copy(obn->data);
                                                didit = 1;
                                        }
-                                       id->us--;
+                                       id_us_min(id);
                                }
                                break;
                        case OB_SURF:
@@ -1972,7 +1972,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base
                                                obn->data = BKE_curve_copy(obn->data);
                                                didit = 1;
                                        }
-                                       id->us--;
+                                       id_us_min(id);
                                }
                                break;
                        case OB_FONT:
@@ -1982,7 +1982,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base
                                                obn->data = BKE_curve_copy(obn->data);
                                                didit = 1;
                                        }
-                                       id->us--;
+                                       id_us_min(id);
                                }
                                break;
                        case OB_MBALL:
@@ -1992,7 +1992,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base
                                                obn->data = BKE_mball_copy(obn->data);
                                                didit = 1;
                                        }
-                                       id->us--;
+                                       id_us_min(id);
                                }
                                break;
                        case OB_LAMP:
@@ -2002,7 +2002,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base
                                                obn->data = BKE_lamp_copy(obn->data);
                                                didit = 1;
                                        }
-                                       id->us--;
+                                       id_us_min(id);
                                }
                                break;
                        case OB_ARMATURE:
@@ -2016,7 +2016,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base
                                                BKE_pose_rebuild(obn, obn->data);
                                                didit = 1;
                                        }
-                                       id->us--;
+                                       id_us_min(id);
                                }
                                break;
                        case OB_LATTICE:
@@ -2026,7 +2026,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base
                                                obn->data = BKE_lattice_copy(obn->data);
                                                didit = 1;
                                        }
-                                       id->us--;
+                                       id_us_min(id);
                                }
                                break;
                        case OB_CAMERA:
@@ -2036,7 +2036,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base
                                                obn->data = BKE_camera_copy(obn->data);
                                                didit = 1;
                                        }
-                                       id->us--;
+                                       id_us_min(id);
                                }
                                break;
                        case OB_SPEAKER:
@@ -2046,7 +2046,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base
                                                obn->data = BKE_speaker_copy(obn->data);
                                                didit = 1;
                                        }
-                                       id->us--;
+                                       id_us_min(id);
                                }
                                break;
                }
@@ -2083,7 +2083,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base
                                                        ID_NEW_US((*matarar)[a])
                                                        else
                                                                (*matarar)[a] = BKE_material_copy((*matarar)[a]);
-                                                       id->us--;
+                                                       id_us_min(id);
                                                }
                                        }
                                }
index c87eeaeb4a3e5c993f0a2291da73d0f493a6dd82..9b7563ae729a652dd0f693300cf5549e518aef11 100644 (file)
@@ -934,16 +934,20 @@ static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event)
                                                cu1->wordspace = cu->wordspace;
                                                cu1->ulpos = cu->ulpos;
                                                cu1->ulheight = cu->ulheight;
-                                               if (cu1->vfont) cu1->vfont->id.us--;
+                                               if (cu1->vfont)
+                                                       id_us_min(&cu1->vfont->id);
                                                cu1->vfont = cu->vfont;
                                                id_us_plus((ID *)cu1->vfont);
-                                               if (cu1->vfontb) cu1->vfontb->id.us--;
+                                               if (cu1->vfontb)
+                                                       id_us_min(&cu1->vfontb->id);
                                                cu1->vfontb = cu->vfontb;
                                                id_us_plus((ID *)cu1->vfontb);
-                                               if (cu1->vfonti) cu1->vfonti->id.us--;
+                                               if (cu1->vfonti)
+                                                       id_us_min(&cu1->vfonti->id);
                                                cu1->vfonti = cu->vfonti;
                                                id_us_plus((ID *)cu1->vfonti);
-                                               if (cu1->vfontbi) cu1->vfontbi->id.us--;
+                                               if (cu1->vfontbi)
+                                                       id_us_min(&cu1->vfontbi->id);
                                                cu1->vfontbi = cu->vfontbi;
                                                id_us_plus((ID *)cu1->vfontbi);
                                                
index 3d030f1a7709dd15ec99f69340960dfecee69db6..a89ef8b7e8559d5d023a7ba4df8bbb28b58a587c 100644 (file)
@@ -1555,7 +1555,7 @@ static int make_links_data_exec(bContext *C, wmOperator *op)
 
                                switch (type) {
                                        case MAKE_LINKS_OBDATA: /* obdata */
-                                               obdata_id->us--;
+                                               id_us_min(obdata_id);
 
                                                obdata_id = ob_src->data;
                                                id_us_plus(obdata_id);
@@ -1624,16 +1624,20 @@ static int make_links_data_exec(bContext *C, wmOperator *op)
                                                        break;
                                                }
 
-                                               if (cu_dst->vfont) cu_dst->vfont->id.us--;
+                                               if (cu_dst->vfont)
+                                                       id_us_min(&cu_dst->vfont->id);
                                                cu_dst->vfont = cu_src->vfont;
                                                id_us_plus((ID *)cu_dst->vfont);
-                                               if (cu_dst->vfontb) cu_dst->vfontb->id.us--;
+                                               if (cu_dst->vfontb)
+                                                       id_us_min(&cu_dst->vfontb->id);
                                                cu_dst->vfontb = cu_src->vfontb;
                                                id_us_plus((ID *)cu_dst->vfontb);
-                                               if (cu_dst->vfonti) cu_dst->vfonti->id.us--;
+                                               if (cu_dst->vfonti)
+                                                       id_us_min(&cu_dst->vfonti->id);
                                                cu_dst->vfonti = cu_src->vfonti;
                                                id_us_plus((ID *)cu_dst->vfonti);
-                                               if (cu_dst->vfontbi) cu_dst->vfontbi->id.us--;
+                                               if (cu_dst->vfontbi)
+                                                       id_us_min(&cu_dst->vfontbi->id);
                                                cu_dst->vfontbi = cu_src->vfontbi;
                                                id_us_plus((ID *)cu_dst->vfontbi);
 
@@ -1758,7 +1762,7 @@ static void single_object_users(Main *bmain, Scene *scene, View3D *v3d, const in
                                }
                                base->flag = obn->flag;
 
-                               ob->id.us--;
+                               id_us_min(&ob->id);
                        }
                }
        }
@@ -1826,11 +1830,11 @@ static void new_id_matar(Material **matar, const int totcol)
                        if (id->newid) {
                                matar[a] = (Material *)id->newid;
                                id_us_plus(id->newid);
-                               id->us--;
+                               id_us_min(id);
                        }
                        else if (id->us > 1) {
                                matar[a] = BKE_material_copy(matar[a]);
-                               id->us--;
+                               id_us_min(id);
                                id->newid = (ID *)matar[a];
                        }
                }
@@ -1912,7 +1916,7 @@ static void single_obdata_users(Main *bmain, Scene *scene, const int flag)
                                 */
                                BKE_animdata_copy_id_action((ID *)ob->data);
 
-                               id->us--;
+                               id_us_min(id);
                                id->newid = ob->data;
                        }
                }
@@ -1966,7 +1970,7 @@ static void single_mat_users(Scene *scene, const int flag, const bool do_texture
                                                        for (b = 0; b < MAX_MTEX; b++) {
                                                                if (ma->mtex[b] && (tex = ma->mtex[b]->tex)) {
                                                                        if (tex->id.us > 1) {
-                                                                               tex->id.us--;
+                                                                               id_us_min(&tex->id);
                                                                                tex = BKE_texture_copy(tex);
                                                                                BKE_animdata_copy_id_action(&tex->id);
                                                                                man->mtex[b]->tex = tex;
@@ -1991,13 +1995,13 @@ static void do_single_tex_user(Tex **from)
        if (tex->id.newid) {
                *from = (Tex *)tex->id.newid;
                id_us_plus(tex->id.newid);
-               tex->id.us--;
+               id_us_min(&tex->id);
        }
        else if (tex->id.us > 1) {
                texn = BKE_texture_copy(tex);
                BKE_animdata_copy_id_action(&texn->id);
                tex->id.newid = (ID *)texn;
-               tex->id.us--;
+               id_us_min(&tex->id);
                *from = texn;
        }
 }
index 337e7e999297be755ca218634b070ece650baae4..6d143fb13f3dc1d1acd0b75a64731b2748f58cb9 100644 (file)
@@ -202,7 +202,7 @@ static int new_particle_settings_exec(bContext *C, wmOperator *UNUSED(op))
        ob= ptr.id.data;
 
        if (psys->part)
-               psys->part->id.us--;
+               id_us_min(&psys->part->id);
 
        psys->part = part;
 
index 2e07e19e3665a1b87c5381ff610193648abdca82..b540b9df16fe0297f5b567758baaa11e0c797414 100644 (file)
@@ -481,7 +481,7 @@ static int new_material_exec(bContext *C, wmOperator *UNUSED(op))
        if (prop) {
                /* when creating new ID blocks, use is already 1, but RNA
                 * pointer use also increases user, so this compensates it */
-               ma->id.us--;
+               id_us_min(&ma->id);
 
                RNA_id_pointer_create(&ma->id, &idptr);
                RNA_property_pointer_set(&ptr, prop, idptr);
@@ -530,7 +530,7 @@ static int new_texture_exec(bContext *C, wmOperator *UNUSED(op))
        if (prop) {
                /* when creating new ID blocks, use is already 1, but RNA
                 * pointer se also increases user, so this compensates it */
-               tex->id.us--;
+               id_us_min(&tex->id);
 
                if (ptr.id.data && GS(((ID *)ptr.id.data)->name) == ID_MA &&
                    RNA_property_pointer_get(&ptr, prop).id.data == NULL)
@@ -593,7 +593,7 @@ static int new_world_exec(bContext *C, wmOperator *UNUSED(op))
        if (prop) {
                /* when creating new ID blocks, use is already 1, but RNA
                 * pointer se also increases user, so this compensates it */
-               wo->id.us--;
+               id_us_min(&wo->id);
 
                RNA_id_pointer_create(&wo->id, &idptr);
                RNA_property_pointer_set(&ptr, prop, idptr);
@@ -1039,7 +1039,7 @@ static int freestyle_linestyle_new_exec(bContext *C, wmOperator *op)
                return OPERATOR_CANCELLED;
        }
        if (lineset->linestyle) {
-               lineset->linestyle->id.us--;
+               id_us_min(&lineset->linestyle->id);
                lineset->linestyle = BKE_linestyle_copy(bmain, lineset->linestyle);
        }
        else {
@@ -1826,7 +1826,7 @@ static void paste_mtex_copybuf(ID *id)
                        *mtex = MEM_mallocN(sizeof(MTex), "mtex copy");
                }
                else if ((*mtex)->tex) {
-                       (*mtex)->tex->id.us--;
+                       id_us_min(&(*mtex)->tex->id);
                }
                
                memcpy(*mtex, &mtexcopybuf, sizeof(MTex));
index f8d84cc0276c1ac4fd9800642202b951fa509db2..ffb1898d8161b4850f2fcceb08ea5f04fe39fa1a 100644 (file)
@@ -137,7 +137,7 @@ static int sound_open_exec(bContext *C, wmOperator *op)
        if (pprop->prop) {
                /* when creating new ID blocks, use is already 1, but RNA
                 * pointer se also increases user, so this compensates it */
-               sound->id.us--;
+               id_us_min(&sound->id);
 
                RNA_id_pointer_create(&sound->id, &idptr);
                RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr);
index c351942377327c33a6f96c58c7ba81c2cd6e9497..8ce126b439eb7f21f3cb7456fd07ffc2f9a55333 100644 (file)
@@ -133,7 +133,7 @@ static bAction *action_create_new(bContext *C, bAction *oldact)
         * for that here
         */
        BLI_assert(action->id.us == 1);
-       action->id.us--;
+       id_us_min(&action->id);
        
        /* set ID-Root type */
        if (sa->spacetype == SPACE_ACTION) {
@@ -583,7 +583,7 @@ void ED_animedit_unlink_action(bContext *C, ID *id, AnimData *adt, bAction *act,
                /* Clear Fake User */
                if (act->id.flag & LIB_FAKEUSER) {
                        act->id.flag &= ~LIB_FAKEUSER;
-                       act->id.us--;
+                       id_us_min(&act->id);
                }
        }
        
index af3d460fe0fa7587f4a5675f43fd9693343206ca..f66425e0a1a02fc30fd49523a82013595681860b 100644 (file)
@@ -57,6 +57,7 @@
 #include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_report.h"
+#include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_movieclip.h"
 #include "BKE_sound.h"
@@ -234,7 +235,7 @@ static int open_exec(bContext *C, wmOperator *op)
        if (pprop->prop) {
                /* when creating new ID blocks, use is already 1, but RNA
                 * pointer se also increases user, so this compensates it */
-               clip->id.us--;
+               id_us_min(&clip->id);
 
                RNA_id_pointer_create(&clip->id, &idptr);
                RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr);
index ab062eb133b0d00a5d5a133243b146314e98afed..a07d274b69b8a1521536ef8314fcdf6f9b2d5318 100644 (file)
@@ -1169,7 +1169,7 @@ static int image_open_exec(bContext *C, wmOperator *op)
        if (iod->pprop.prop) {
                /* when creating new ID blocks, use is already 1, but RNA
                 * pointer se also increases user, so this compensates it */
-               ima->id.us--;
+               id_us_min(&ima->id);
                if ((frame_seq_len > 1) && ima->source == IMA_SRC_FILE) {
                        ima->source = IMA_SRC_SEQUENCE;
                }
@@ -2276,7 +2276,7 @@ static int image_new_exec(bContext *C, wmOperator *op)
        if (prop) {
                /* when creating new ID blocks, use is already 1, but RNA
                 * pointer se also increases user, so this compensates it */
-               ima->id.us--;
+               id_us_min(&ima->id);
 
                RNA_id_pointer_create(&ima->id, &idptr);
                RNA_property_pointer_set(&ptr, prop, idptr);
index 8802ab527257cfea62a54b65a4d69c6c34655aee..874e54ba5e7cc59d4f5f7776b9e9712561fb5756 100644 (file)
@@ -52,6 +52,7 @@
 
 #include "BKE_action.h"
 #include "BKE_context.h"
+#include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_sca.h"
 
@@ -308,12 +309,13 @@ static void do_logic_buts(bContext *C, void *UNUSED(arg), int event)
                                                }
                                                
                                                if (sa->sound)
-                                                       ((ID *)sa->sound)->us--;
+                                                       id_us_min(((ID *)sa->sound));
                                                
                                                sa->sound= (struct bSound *)sound;
                                                
-                                               if (sound)
-                                                       sound->us++;
+                                               if (sound) {
+                                                       id_us_plus(sound);
+                                               }
                                                
                                                sa->sndnr= 0;
                                                didit= 1;
index f7673d86f94d0accb8a585871a556cb52f61f4f5..36a4800b59da8e725247157a7361f07752319ee6 100644 (file)
@@ -1953,7 +1953,7 @@ static int nlaedit_apply_scale_exec(bContext *C, wmOperator *UNUSED(op))
                                        bAction *act = BKE_action_copy(strip->act);
                                        
                                        /* set this as the new referenced action, decrementing the users of the old one */
-                                       strip->act->id.us--;
+                                       id_us_min(&strip->act->id);
                                        strip->act = act;
                                }
                                
index c830b94588cd6cd329275de6bc9d374ebd9f89ef..960a561409711abca2a35ea4d051b62b5ecd96f3 100644 (file)
@@ -247,7 +247,7 @@ static void node_browse_tex_cb(bContext *C, void *ntree_v, void *node_v)
        if (node->menunr < 1) return;
        
        if (node->id) {
-               node->id->us--;
+               id_us_min(node->id);
                node->id = NULL;
        }
        tex = BLI_findlink(&bmain->tex, node->menunr - 1);
index ab7fa51856acb96829832ee14aaefb90776d5e01..aef1116b0b8e7432afd8e564ae91bad388607099 100644 (file)
@@ -487,7 +487,7 @@ static int new_node_tree_exec(bContext *C, wmOperator *op)
                /* RNA_property_pointer_set increases the user count,
                 * fixed here as the editor is the initial user.
                 */
-               ntree->id.us--;
+               id_us_min(&ntree->id);
 
                RNA_id_pointer_create(&ntree->id, &idptr);
                RNA_property_pointer_set(&ptr, prop, idptr);
index ffd51bcc44e75aed7df13d508e6e9bb553b465a3..108f12f592f39423df482f0763cfde24b3d36fe0 100644 (file)
@@ -1669,7 +1669,7 @@ static int node_delete_exec(bContext *C, wmOperator *UNUSED(op))
                if (node->flag & SELECT) {
                        /* check id user here, nodeFreeNode is called for free dbase too */
                        if (node->id)
-                               node->id->us--;
+                               id_us_min(node->id);
                        nodeFreeNode(snode->edittree, node);
                }
        }
@@ -1760,7 +1760,7 @@ static int node_delete_reconnect_exec(bContext *C, wmOperator *UNUSED(op))
                        
                        /* check id user here, nodeFreeNode is called for free dbase too */
                        if (node->id)
-                               node->id->us--;
+                               id_us_min(node->id);
                        nodeFreeNode(snode->edittree, node);
                }
        }
index ec6ef3c4697ea24b7601502a596a8ba27c0e7dd8..d8dca7b63d4c3659cc007aa55daea295298881fd 100644 (file)
@@ -150,7 +150,7 @@ static void node_remove_linked(bNodeTree *ntree, bNode *rem_node)
 
                if (node->flag & NODE_TEST) {
                        if (node->id)
-                               node->id->us--;
+                               id_us_min(node->id);
                        nodeFreeNode(ntree, node);
                }
        }
index a209681e18c137a7ee96da9c115802e58813d961..c0464c84061ac50ba92b3f8a200f362dc0dcf861 100644 (file)
@@ -172,7 +172,7 @@ static void unlink_material_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeEl
        if (LIKELY(matar != NULL)) {
                for (a = 0; a < totcol; a++) {
                        if (a == te->index && matar[a]) {
-                               matar[a]->id.us--;
+                               id_us_min(&matar[a]->id);
                                matar[a] = NULL;
                        }
                }
@@ -208,7 +208,7 @@ static void unlink_texture_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeEle
        for (a = 0; a < MAX_MTEX; a++) {
                if (a == te->index && mtex[a]) {
                        if (mtex[a]->tex) {
-                               mtex[a]->tex->id.us--;
+                               id_us_min(&mtex[a]->tex->id);
                                mtex[a]->tex = NULL;
                        }
                }
index 9d8db67b3ee0a69fa9129c3b69886c92d0868baa..e9a4bc81e14adbe78113fc4bcb29a81ba3d09036 100644 (file)
@@ -2386,7 +2386,7 @@ static int sequencer_separate_images_exec(bContext *C, wmOperator *op)
                        /* remove seq so overlap tests don't conflict,
                         * see seq_free_sequence below for the real free'ing */
                        BLI_remlink(ed->seqbasep, seq);
-                       /* if (seq->ipo) seq->ipo->id.us--; */
+                       /* if (seq->ipo) id_us_min(&seq->ipo->id); */
                        /* XXX, remove fcurve and assign to split image strips */
 
                        start_ofs = cfra = BKE_sequence_tx_get_final_left(seq, false);
index b57941c2f1f299fa254ffbc3c7cd6c3b43fed14b..baafaece2e5beeb398db168e99b9a8a14c5b09e6 100644 (file)
@@ -73,6 +73,7 @@
 #include "BKE_depsgraph.h"
 #include "BKE_fcurve.h"
 #include "BKE_lattice.h"
+#include "BKE_library.h"
 #include "BKE_nla.h"
 #include "BKE_context.h"
 #include "BKE_paint.h"
@@ -278,7 +279,7 @@ static void animrecord_check_state(Scene *scene, ID *id, wmTimer *animtimer)
                                        NlaStrip *strip = add_nlastrip_to_stack(adt, adt->action);
                                        
                                        /* clear reference to action now that we've pushed it onto the stack */
-                                       adt->action->id.us--;
+                                       id_us_min(&adt->action->id);
                                        adt->action = NULL;
                                        
                                        /* adjust blending + extend so that they will behave correctly */
index 46724ff530a1474f65d42bf03ef1ec70f90a6258..2244e9196de8bbc10ea2e272b4f46dc10c689263 100644 (file)
@@ -698,10 +698,10 @@ void FRS_paste_active_lineset(FreestyleConfig *config)
 
        if (lineset) {
                if (lineset->linestyle)
-                       lineset->linestyle->id.us--;
+                       id_us_min(&lineset->linestyle->id);
                lineset->linestyle = lineset_buffer.linestyle;
                if (lineset->linestyle)
-                       lineset->linestyle->id.us++;
+                       id_us_plus(&lineset->linestyle->id);
                lineset->flags = lineset_buffer.flags;
                lineset->selection = lineset_buffer.selection;
                lineset->qi = lineset_buffer.qi;
@@ -710,12 +710,12 @@ void FRS_paste_active_lineset(FreestyleConfig *config)
                lineset->edge_types = lineset_buffer.edge_types;
                lineset->exclude_edge_types = lineset_buffer.exclude_edge_types;
                if (lineset->group) {
-                       lineset->group->id.us--;
+                       id_us_min(&lineset->group->id);
                        lineset->group = NULL;
                }
                if (lineset_buffer.group) {
                        lineset->group = lineset_buffer.group;
-                       lineset->group->id.us++;
+                       id_us_plus(&lineset->group->id);
                }
                strcpy(lineset->name, lineset_buffer.name);
                BKE_freestyle_lineset_unique_name(config, lineset);
index 2766540ab6997cf352bfee23f01aaa8999e009ba..f7cc4187dc648081914f37106cfe136296bf4c10 100644 (file)
@@ -487,12 +487,12 @@ static void rna_FieldSettings_update(Main *UNUSED(bmain), Scene *UNUSED(scene),
                ParticleSettings *part = (ParticleSettings *)ptr->id.data;
 
                if (part->pd->forcefield != PFIELD_TEXTURE && part->pd->tex) {
-                       part->pd->tex->id.us--;
+                       id_us_min(&part->pd->tex->id);
                        part->pd->tex = NULL;
                }
 
                if (part->pd2 && part->pd2->forcefield != PFIELD_TEXTURE && part->pd2->tex) {
-                       part->pd2->tex->id.us--;
+                       id_us_min(&part->pd2->tex->id);
                        part->pd2->tex = NULL;
                }
 
@@ -504,7 +504,7 @@ static void rna_FieldSettings_update(Main *UNUSED(bmain), Scene *UNUSED(scene),
                Object *ob = (Object *)ptr->id.data;
 
                if (ob->pd->forcefield != PFIELD_TEXTURE && ob->pd->tex) {
-                       ob->pd->tex->id.us--;
+                       id_us_min(&ob->pd->tex->id);
                        ob->pd->tex = NULL;
                }
 
index f27e620fa5b2a27d41122c128d968f951c296038..bac6b88feb9914a070372cf26a4895d330a35dd3 100644 (file)
@@ -751,13 +751,13 @@ static void rna_particle_settings_set(PointerRNA *ptr, PointerRNA value)
 
        if (psys->part) {
                old_type = psys->part->type;
-               psys->part->id.us--;
+               id_us_min(&psys->part->id);
        }
 
        psys->part = (ParticleSettings *)value.data;
 
        if (psys->part) {
-               psys->part->id.us++;
+               id_us_plus(&psys->part->id);
                psys_check_boid_data(psys);
                if (old_type != psys->part->type)
                        psys->recalc |= PSYS_RECALC_TYPE;
index 1149214e533f58b767c0c84407fcea8b0a43ca93..984e5d203a72831d07d9700ebfb43270bb8089e6 100644 (file)
@@ -508,7 +508,7 @@ static void rna_Scene_object_unlink(Scene *scene, ReportList *reports, Object *o
        BKE_scene_base_unlink(scene, base);
        MEM_freeN(base);
 
-       ob->id.us--;
+       id_us_min(&ob->id);
 
        /* needed otherwise the depgraph will contain freed objects which can crash, see [#20958] */
        DAG_relations_tag_update(G.main);
@@ -1815,9 +1815,9 @@ static void rna_FreestyleLineSet_linestyle_set(PointerRNA *ptr, PointerRNA value
        FreestyleLineSet *lineset = (FreestyleLineSet *)ptr->data;
 
        if (lineset->linestyle)
-               lineset->linestyle->id.us--;
+               id_us_min(&lineset->linestyle->id);
        lineset->linestyle = (FreestyleLineStyle *)value.data;
-       lineset->linestyle->id.us++;
+       id_us_plus(&lineset->linestyle->id);
 }
 
 static FreestyleLineSet *rna_FreestyleSettings_lineset_add(
index 95d8fe1f294d584cc34fb4c2b0d227f03e3fda55..6cbb8e08cf5974b59f881c60a48804de08b022c6 100644 (file)
@@ -1426,7 +1426,7 @@ RAS_MeshObject *KX_BlenderSceneConverter::ConvertMeshSpecial(KX_Scene *kx_scene,
                printf("Mesh has a user \"%s\"\n", name);
 #endif
                me = (ID*)BKE_mesh_copy_ex(from_maggie, (Mesh*)me);
-               me->us--;
+               id_us_min(me);
        }
        BLI_remlink(&from_maggie->mesh, me); /* even if we made the copy it needs to be removed */
        BLI_addtail(&maggie->mesh, me);
@@ -1450,7 +1450,7 @@ RAS_MeshObject *KX_BlenderSceneConverter::ConvertMeshSpecial(KX_Scene *kx_scene,
                                Material *mat_new = BKE_material_copy(mat_old);
 
                                mat_new->id.flag |= LIB_DOIT;
-                               mat_old->id.us--;
+                               id_us_min(&mat_old->id);
 
                                BLI_remlink(&G.main->mat, mat_new); // BKE_material_copy uses G.main, and there is no BKE_material_copy_ex
                                BLI_addtail(&maggie->mat, mat_new);
@@ -1461,8 +1461,8 @@ RAS_MeshObject *KX_BlenderSceneConverter::ConvertMeshSpecial(KX_Scene *kx_scene,
                                for (int j = i + 1; j < mesh->totcol; j++) {
                                        if (mesh->mat[j] == mat_old) {
                                                mesh->mat[j] = mat_new;
-                                               mat_new->id.us++;
-                                               mat_old->id.us--;
+                                               id_us_plus(&mat_new->id);
+                                               id_us_min(&mat_old->id);
                                        }
                                }
                        }