diff options
Diffstat (limited to 'source/blender/blenkernel')
31 files changed, 175 insertions, 141 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(<_new->id); + id_us_min(<->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); } } } |