Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2015-11-09 21:47:10 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2015-11-09 23:00:53 +0300
commit865796375bcfa6be4288cca4243dddcb4092f70b (patch)
tree5264d4b9b0f9d392b6e1b942e0f6fd802de1fff4 /source
parentcf959a879eb5ffbdfa573c5f3a00965e69d7a976 (diff)
Cleanup: avoid incrementing/decrementing id->us outside of BKE_library.
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...).
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/intern/DerivedMesh.c4
-rw-r--r--source/blender/blenkernel/intern/anim_sys.c4
-rw-r--r--source/blender/blenkernel/intern/armature.c4
-rw-r--r--source/blender/blenkernel/intern/brush.c10
-rw-r--r--source/blender/blenkernel/intern/camera.c4
-rw-r--r--source/blender/blenkernel/intern/curve.c17
-rw-r--r--source/blender/blenkernel/intern/effect.c3
-rw-r--r--source/blender/blenkernel/intern/font.c2
-rw-r--r--source/blender/blenkernel/intern/freestyle.c13
-rw-r--r--source/blender/blenkernel/intern/idprop.c5
-rw-r--r--source/blender/blenkernel/intern/image.c10
-rw-r--r--source/blender/blenkernel/intern/ipo.c37
-rw-r--r--source/blender/blenkernel/intern/lamp.c10
-rw-r--r--source/blender/blenkernel/intern/lattice.c4
-rw-r--r--source/blender/blenkernel/intern/library.c1
-rw-r--r--source/blender/blenkernel/intern/linestyle.c12
-rw-r--r--source/blender/blenkernel/intern/mask.c4
-rw-r--r--source/blender/blenkernel/intern/material.c47
-rw-r--r--source/blender/blenkernel/intern/mball.c7
-rw-r--r--source/blender/blenkernel/intern/mesh.c21
-rw-r--r--source/blender/blenkernel/intern/movieclip.c2
-rw-r--r--source/blender/blenkernel/intern/nla.c3
-rw-r--r--source/blender/blenkernel/intern/node.c10
-rw-r--r--source/blender/blenkernel/intern/object.c16
-rw-r--r--source/blender/blenkernel/intern/particle.c12
-rw-r--r--source/blender/blenkernel/intern/scene.c4
-rw-r--r--source/blender/blenkernel/intern/sequencer.c2
-rw-r--r--source/blender/blenkernel/intern/sound.c2
-rw-r--r--source/blender/blenkernel/intern/speaker.c8
-rw-r--r--source/blender/blenkernel/intern/texture.c28
-rw-r--r--source/blender/blenkernel/intern/world.c10
-rw-r--r--source/blender/collada/DocumentImporter.cpp4
-rw-r--r--source/blender/collada/MeshImporter.cpp2
-rw-r--r--source/blender/editors/curve/editcurve.c3
-rw-r--r--source/blender/editors/curve/editfont.c5
-rw-r--r--source/blender/editors/mesh/meshtools.c6
-rw-r--r--source/blender/editors/object/object_add.c44
-rw-r--r--source/blender/editors/object/object_edit.c12
-rw-r--r--source/blender/editors/object/object_relations.c28
-rw-r--r--source/blender/editors/physics/particle_object.c2
-rw-r--r--source/blender/editors/render/render_shading.c10
-rw-r--r--source/blender/editors/sound/sound_ops.c2
-rw-r--r--source/blender/editors/space_action/action_data.c4
-rw-r--r--source/blender/editors/space_clip/clip_ops.c3
-rw-r--r--source/blender/editors/space_image/image_ops.c4
-rw-r--r--source/blender/editors/space_logic/logic_window.c8
-rw-r--r--source/blender/editors/space_nla/nla_edit.c2
-rw-r--r--source/blender/editors/space_node/drawnode.c2
-rw-r--r--source/blender/editors/space_node/node_add.c2
-rw-r--r--source/blender/editors/space_node/node_edit.c4
-rw-r--r--source/blender/editors/space_node/node_templates.c2
-rw-r--r--source/blender/editors/space_outliner/outliner_tools.c4
-rw-r--r--source/blender/editors/space_sequencer/sequencer_edit.c2
-rw-r--r--source/blender/editors/transform/transform_generics.c3
-rw-r--r--source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp8
-rw-r--r--source/blender/makesrna/intern/rna_object_force.c6
-rw-r--r--source/blender/makesrna/intern/rna_particle.c4
-rw-r--r--source/blender/makesrna/intern/rna_scene.c6
-rw-r--r--source/gameengine/Converter/KX_BlenderSceneConverter.cpp8
59 files changed, 278 insertions, 228 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index a5a29f667e5..3c83fbe6a01 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -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;
}
diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c
index 8010d3450cb..2ddf01433eb 100644
--- a/source/blender/blenkernel/intern/anim_sys.c
+++ b/source/blender/blenkernel/intern/anim_sys.c
@@ -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);
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index fde25784c22..0d757246b1c 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -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);
}
}
}
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 95b65f52bd0..201750df5a7 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -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;
}
diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c
index 46b74c58965..73b1f0e53f6 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -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);
}
}
}
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index 3e0bdbe31af..22358256f8c 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -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);
}
}
}
diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c
index e66fa86c4b1..30696012221 100644
--- a/source/blender/blenkernel/intern/effect.c
+++ b/source/blender/blenkernel/intern/effect.c
@@ -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);
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index b12e16d9502..e8bfa27c662 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -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;
diff --git a/source/blender/blenkernel/intern/freestyle.c b/source/blender/blenkernel/intern/freestyle.c
index f6c4263cff7..3a15be5a09d 100644
--- a/source/blender/blenkernel/intern/freestyle.c
+++ b/source/blender/blenkernel/intern/freestyle.c
@@ -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);
diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c
index 4d83f8cf916..86d010f5f7c 100644
--- a/source/blender/blenkernel/intern/idprop.c
+++ b/source/blender/blenkernel/intern/idprop.c
@@ -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));
}
/** \} */
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index ff305434b1b..9dabe6ba56b 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -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)
diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c
index 0c3fd48628f..8985dd372a6 100644
--- a/source/blender/blenkernel/intern/ipo.c
+++ b/source/blender/blenkernel/intern/ipo.c
@@ -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;
}
}
diff --git a/source/blender/blenkernel/intern/lamp.c b/source/blender/blenkernel/intern/lamp.c
index 8e350896eb8..7fcbd9cafb7 100644
--- a/source/blender/blenkernel/intern/lamp.c
+++ b/source/blender/blenkernel/intern/lamp.c
@@ -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);
diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c
index 0e5228a6db4..1992eabafec 100644
--- a/source/blender/blenkernel/intern/lattice.c
+++ b/source/blender/blenkernel/intern/lattice.c
@@ -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);
}
}
}
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index c618795eb52..90cd950a78d 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -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) {
diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c
index 93d2b549fee..5a1dfc04045 100644
--- a/source/blender/blenkernel/intern/linestyle.c
+++ b/source/blender/blenkernel/intern/linestyle.c
@@ -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;
diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c
index 141597e859c..b79c72a4251 100644
--- a/source/blender/blenkernel/intern/mask.c
+++ b/source/blender/blenkernel/intern/mask.c
@@ -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) {
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index a69b5fd87b5..ba81f68ff23 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -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) {
diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c
index bd9fd331584..1d409e9ffe8 100644
--- a/source/blender/blenkernel/intern/mball.c
+++ b/source/blender/blenkernel/intern/mball.c
@@ -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);
}
}
}
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 318040db2be..12559e276d3 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -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);
}
}
}
diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c
index 432ae32f02b..0828f4e9e0e 100644
--- a/source/blender/blenkernel/intern/movieclip.c
+++ b/source/blender/blenkernel/intern/movieclip.c
@@ -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;
diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c
index 65245477c7f..0527df67033 100644
--- a/source/blender/blenkernel/intern/nla.c
+++ b/source/blender/blenkernel/intern/nla.c
@@ -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;
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index 68d9609e069..70f2f9d26e0 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -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 */
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 456791e99fc..1e345605ec2 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -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;
}
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index 29bd27de2e6..ae18c6f4aad 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -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);
}
}
}
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 6fe92a4ac23..82a040f4ca0 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -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;
}
diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c
index 4a24b149c34..45d33e51e18 100644
--- a/source/blender/blenkernel/intern/sequencer.c
+++ b/source/blender/blenkernel/intern/sequencer.c
@@ -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) {
diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c
index 7e7cc8745fd..69f4dbcd502 100644
--- a/source/blender/blenkernel/intern/sound.c
+++ b/source/blender/blenkernel/intern/sound.c
@@ -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;
diff --git a/source/blender/blenkernel/intern/speaker.c b/source/blender/blenkernel/intern/speaker.c
index 30296c7813c..3b5b8ce3f9a 100644
--- a/source/blender/blenkernel/intern/speaker.c
+++ b/source/blender/blenkernel/intern/speaker.c
@@ -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);
}
diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c
index 463ca250ad5..d353042b711 100644
--- a/source/blender/blenkernel/intern/texture.c
+++ b/source/blender/blenkernel/intern/texture.c
@@ -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);
}
}
}
diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c
index 88c98b6d9d8..17a2e7f14fd 100644
--- a/source/blender/blenkernel/intern/world.c
+++ b/source/blender/blenkernel/intern/world.c
@@ -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);
}
}
}
diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp
index 674a79f0fe7..498e65790f3 100644
--- a/source/blender/collada/DocumentImporter.cpp
+++ b/source/blender/collada/DocumentImporter.cpp
@@ -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;
diff --git a/source/blender/collada/MeshImporter.cpp b/source/blender/collada/MeshImporter.cpp
index 2adbdd27cdf..64df42fc823 100644
--- a/source/blender/collada/MeshImporter.cpp
+++ b/source/blender/collada/MeshImporter.cpp
@@ -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)
diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c
index f7dab0c0935..5a47cc148d2 100644
--- a/source/blender/editors/curve/editcurve.c
+++ b/source/blender/editors/curve/editcurve.c
@@ -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);
diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c
index ea6b6154be8..1eee5d04c56 100644
--- a/source/blender/editors/curve/editfont.c
+++ b/source/blender/editors/curve/editfont.c
@@ -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);
diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c
index 2491685161c..dee003135a2 100644
--- a/source/blender/editors/mesh/meshtools.c
+++ b/source/blender/editors/mesh/meshtools.c
@@ -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);
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
index 269700c3aef..2cead58300d 100644
--- a/source/blender/editors/object/object_add.c
+++ b/source/blender/editors/object/object_add.c
@@ -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);
}
}
}
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index c87eeaeb4a3..9b7563ae729 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -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);
diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c
index 3d030f1a770..a89ef8b7e85 100644
--- a/source/blender/editors/object/object_relations.c
+++ b/source/blender/editors/object/object_relations.c
@@ -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;
}
}
diff --git a/source/blender/editors/physics/particle_object.c b/source/blender/editors/physics/particle_object.c
index 337e7e99929..6d143fb13f3 100644
--- a/source/blender/editors/physics/particle_object.c
+++ b/source/blender/editors/physics/particle_object.c
@@ -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;
diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c
index 2e07e19e366..b540b9df16f 100644
--- a/source/blender/editors/render/render_shading.c
+++ b/source/blender/editors/render/render_shading.c
@@ -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));
diff --git a/source/blender/editors/sound/sound_ops.c b/source/blender/editors/sound/sound_ops.c
index f8d84cc0276..ffb1898d816 100644
--- a/source/blender/editors/sound/sound_ops.c
+++ b/source/blender/editors/sound/sound_ops.c
@@ -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);
diff --git a/source/blender/editors/space_action/action_data.c b/source/blender/editors/space_action/action_data.c
index c3519423773..8ce126b439e 100644
--- a/source/blender/editors/space_action/action_data.c
+++ b/source/blender/editors/space_action/action_data.c
@@ -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);
}
}
diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c
index af3d460fe0f..f66425e0a1a 100644
--- a/source/blender/editors/space_clip/clip_ops.c
+++ b/source/blender/editors/space_clip/clip_ops.c
@@ -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);
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index ab062eb133b..a07d274b69b 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -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);
diff --git a/source/blender/editors/space_logic/logic_window.c b/source/blender/editors/space_logic/logic_window.c
index 8802ab52725..874e54ba5e7 100644
--- a/source/blender/editors/space_logic/logic_window.c
+++ b/source/blender/editors/space_logic/logic_window.c
@@ -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;
diff --git a/source/blender/editors/space_nla/nla_edit.c b/source/blender/editors/space_nla/nla_edit.c
index f7673d86f94..36a4800b59d 100644
--- a/source/blender/editors/space_nla/nla_edit.c
+++ b/source/blender/editors/space_nla/nla_edit.c
@@ -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;
}
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index c830b94588c..960a5614097 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -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);
diff --git a/source/blender/editors/space_node/node_add.c b/source/blender/editors/space_node/node_add.c
index ab7fa51856a..aef1116b0b8 100644
--- a/source/blender/editors/space_node/node_add.c
+++ b/source/blender/editors/space_node/node_add.c
@@ -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);
diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c
index ffd51bcc44e..108f12f592f 100644
--- a/source/blender/editors/space_node/node_edit.c
+++ b/source/blender/editors/space_node/node_edit.c
@@ -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);
}
}
diff --git a/source/blender/editors/space_node/node_templates.c b/source/blender/editors/space_node/node_templates.c
index ec6ef3c4697..d8dca7b63d4 100644
--- a/source/blender/editors/space_node/node_templates.c
+++ b/source/blender/editors/space_node/node_templates.c
@@ -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);
}
}
diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c
index a209681e18c..c0464c84061 100644
--- a/source/blender/editors/space_outliner/outliner_tools.c
+++ b/source/blender/editors/space_outliner/outliner_tools.c
@@ -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;
}
}
diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c
index 9d8db67b3ee..e9a4bc81e14 100644
--- a/source/blender/editors/space_sequencer/sequencer_edit.c
+++ b/source/blender/editors/space_sequencer/sequencer_edit.c
@@ -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);
diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c
index b57941c2f1f..baafaece2e5 100644
--- a/source/blender/editors/transform/transform_generics.c
+++ b/source/blender/editors/transform/transform_generics.c
@@ -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 */
diff --git a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
index 46724ff530a..2244e9196de 100644
--- a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
+++ b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
@@ -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);
diff --git a/source/blender/makesrna/intern/rna_object_force.c b/source/blender/makesrna/intern/rna_object_force.c
index 2766540ab69..f7cc4187dc6 100644
--- a/source/blender/makesrna/intern/rna_object_force.c
+++ b/source/blender/makesrna/intern/rna_object_force.c
@@ -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;
}
diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c
index f27e620fa5b..bac6b88feb9 100644
--- a/source/blender/makesrna/intern/rna_particle.c
+++ b/source/blender/makesrna/intern/rna_particle.c
@@ -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;
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 1149214e533..984e5d203a7 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -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(
diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
index 95d8fe1f294..6cbb8e08cf5 100644
--- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
+++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
@@ -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);
}
}
}