Discussion:
[Bf-blender-cvs] [cf959a8] master: Cleanup: readfile: get rid of USER_ONE, replaced by USER_REAL everywhere.
Bastien Montagne
2015-11-09 20:07:45 UTC
Permalink
Commit: cf959a879eb5ffbdfa573c5f3a00965e69d7a976
Author: Bastien Montagne
Date: Mon Nov 9 16:04:51 2015 +0100
Branches: master
https://developer.blender.org/rBcf959a879eb5ffbdfa573c5f3a00965e69d7a976

Cleanup: readfile: get rid of USER_ONE, replaced by USER_REAL everywhere.

USER_ONE was only ensuring id->us was non-zero, while USER_REAL ensures
it is non-zero **and** >1 in case fake_user flag is set (which at least
ensures us unsetting fake_user won't leave id->us in invalid zero state).

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

M source/blender/blenloader/intern/readfile.c

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

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 6c6af2d..9ebae18 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6348,20 +6348,14 @@ static void lib_link_screen(FileData *fd, Main *main)
/* how to handle user count on pointer restore */
typedef enum ePointerUserMode {
USER_IGNORE = 0, /* ignore user count */
- USER_ONE = 1, /* ensure at least one user (fake also counts) */
- USER_REAL = 2, /* ensure at least one real user (fake user ignored) */
+ USER_REAL = 1, /* ensure at least one real user (fake user ignored) */
} ePointerUserMode;

static bool restore_pointer(ID *id, ID *newid, ePointerUserMode user)
{
if (STREQ(newid->name + 2, id->name + 2)) {
if (newid->lib == id->lib) {
- if (user == USER_ONE) {
- if (newid->us == 0) {
- newid->us++;
- }
- }
- else if (user == USER_REAL) {
+ if (user == USER_REAL) {
id_us_ensure_real(newid);
}
return true;
@@ -6375,7 +6369,6 @@ static bool restore_pointer(ID *id, ID *newid, ePointerUserMode user)
*
* user
* - USER_IGNORE: no usercount change
- * - USER_ONE: ensure a user
* - USER_REAL: ensure a real user (even if a fake one is set)
*/
static void *restore_pointer_by_name(Main *mainp, ID *id, ePointerUserMode user)
@@ -6401,7 +6394,7 @@ static void lib_link_seq_clipboard_pt_restore(ID *id, Main *newmain)
if (id) {
/* clipboard must ensure this */
BLI_assert(id->newid != NULL);
- id->newid = restore_pointer_by_name(newmain, (ID *)id->newid, USER_ONE);
+ id->newid = restore_pointer_by_name(newmain, (ID *)id->newid, USER_REAL);
}
}
static int lib_link_seq_clipboard_cb(Sequence *seq, void *arg_pt)
@@ -6435,7 +6428,7 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc
/* first windowmanager */
for (wm = newmain->wm.first; wm; wm = wm->id.next) {
for (win= wm->windows.first; win; win= win->next) {
- win->screen = restore_pointer_by_name(newmain, (ID *)win->screen, USER_ONE);
+ win->screen = restore_pointer_by_name(newmain, (ID *)win->screen, USER_REAL);

if (win->screen == NULL)
win->screen = curscreen;
@@ -6448,7 +6441,7 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc
for (sc = newmain->screen.first; sc; sc = sc->id.next) {
Scene *oldscene = sc->scene;

- sc->scene= restore_pointer_by_name(newmain, (ID *)sc->scene, USER_ONE);
+ sc->scene= restore_pointer_by_name(newmain, (ID *)sc->scene, USER_REAL);
if (sc->scene == NULL)
sc->scene = curscene;

@@ -6467,10 +6460,10 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc
if (v3d->scenelock)
v3d->camera = NULL; /* always get from scene */
else
- v3d->camera = restore_pointer_by_name(newmain, (ID *)v3d->camera, USER_ONE);
+ v3d->camera = restore_pointer_by_name(newmain, (ID *)v3d->camera, USER_REAL);
if (v3d->camera == NULL)
v3d->camera = sc->scene->camera;
- v3d->ob_centre = restore_pointer_by_name(newmain, (ID *)v3d->ob_centre, USER_ONE);
+ v3d->ob_centre = restore_pointer_by_name(newmain, (ID *)v3d->ob_centre, USER_REAL);

for (bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next) {
if ((bgpic->ima = restore_pointer_by_name(newmain, (ID *)bgpic->ima, USER_IGNORE))) {
@@ -6520,7 +6513,7 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc
bDopeSheet *ads = sipo->ads;

if (ads) {
- ads->source = restore_pointer_by_name(newmain, (ID *)ads->source, USER_ONE);
+ ads->source = restore_pointer_by_name(newmain, (ID *)ads->source, USER_REAL);

if (ads->filter_grp)
ads->filter_grp = restore_pointer_by_name(newmain, (ID *)ads->filter_grp, USER_IGNORE);
@@ -6550,8 +6543,8 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc
else if (sl->spacetype == SPACE_ACTION) {
SpaceAction *saction = (SpaceAction *)sl;

- saction->action = restore_pointer_by_name(newmain, (ID *)saction->action, USER_ONE);
- saction->ads.source = restore_pointer_by_name(newmain, (ID *)saction->ads.source, USER_ONE);
+ saction->action = restore_pointer_by_name(newmain, (ID *)saction->action, USER_REAL);
+ saction->ads.source = restore_pointer_by_name(newmain, (ID *)saction->ads.source, USER_REAL);

if (saction->ads.filter_grp)
saction->ads.filter_grp = restore_pointer_by_name(newmain, (ID *)saction->ads.filter_grp, USER_IGNORE);
@@ -6580,7 +6573,7 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc
/* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data
* so assume that here we're doing for undo only...
*/
- sima->gpd = restore_pointer_by_name(newmain, (ID *)sima->gpd, USER_ONE);
+ sima->gpd = restore_pointer_by_name(newmain, (ID *)sima->gpd, USER_REAL);
sima->mask_info.mask = restore_pointer_by_name(newmain, (ID *)sima->mask_info.mask, USER_REAL);
}
else if (sl->spacetype == SPACE_SEQ) {
@@ -6589,14 +6582,14 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc
/* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data
* so assume that here we're doing for undo only...
*/
- sseq->gpd = restore_pointer_by_name(newmain, (ID *)sseq->gpd, USER_ONE);
+ sseq->gpd = restore_pointer_by_name(newmain, (ID *)sseq->gpd, USER_REAL);
}
else if (sl->spacetype == SPACE_NLA) {
SpaceNla *snla = (SpaceNla *)sl;
bDopeSheet *ads = snla->ads;

if (ads) {
- ads->source = restore_pointer_by_name(newmain, (ID *)ads->source, USER_ONE);
+ ads->source = restore_pointer_by_name(newmain, (ID *)ads->source, USER_REAL);

if (ads->filter_grp)
ads->filter_grp = restore_pointer_by_name(newmain, (ID *)ads->filter_grp, USER_IGNORE);
@@ -6605,13 +6598,13 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc
else if (sl->spacetype == SPACE_TEXT) {
SpaceText *st = (SpaceText *)sl;

- st->text = restore_pointer_by_name(newmain, (ID *)st->text, USER_ONE);
+ st->text = restore_pointer_by_name(newmain, (ID *)st->text, USER_REAL);
if (st->text == NULL) st->text = newmain->text.first;
}
else if (sl->spacetype == SPACE_SCRIPT) {
SpaceScript *scpt = (SpaceScript *)sl;

- scpt->script = restore_pointer_by_name(newmain, (ID *)scpt->script, USER_ONE);
+ scpt->script = restore_pointer_by_name(newmain, (ID *)scpt->script, USER_REAL);

/*sc->script = NULL; - 2.45 set to null, better re-run the script */
if (scpt->script) {
@@ -6649,7 +6642,7 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc
bNodeTree *ntree;

/* node tree can be stored locally in id too, link this first */
- snode->id = restore_pointer_by_name(newmain, snode->id, USER_ONE);
+ snode->id = restore_pointer_by_name(newmain, snode->id, USER_REAL);
snode->from = restore_pointer_by_name(newmain, snode->from, USER_IGNORE);

ntree = nodetree_from_id(snode->id);
@@ -6698,7 +6691,7 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc
else if (sl->spacetype == SPACE_LOGIC) {
SpaceLogic *slogic = (SpaceLogic *)sl;

- slogic->gpd = restore_pointer_by_name(newmain, (ID *)slogic->gpd, USER_ONE);
+ slogic->gpd = restore_pointer_by_name(newmain, (ID *)slogic->gpd, USER_REAL);
}
}
}
Bastien Montagne
2015-11-09 20:07:46 UTC
Permalink
Commit: 865796375bcfa6be4288cca4243dddcb4092f70b
Author: Bastien Montagne
Date: Mon Nov 9 19:47:10 2015 +0100
Branches: master
https://developer.blender.org/rB865796375bcfa6be4288cca4243dddcb4092f70b

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...).

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

M source/blender/blenkernel/intern/DerivedMesh.c
M source/blender/blenkernel/intern/anim_sys.c
M source/blender/blenkernel/intern/armature.c
M source/blender/blenkernel/intern/brush.c
M source/blender/blenkernel/intern/camera.c
M source/blender/blenkernel/intern/curve.c
M source/blender/blenkernel/intern/effect.c
M source/blender/blenkernel/intern/font.c
M source/blender/blenkernel/intern/freestyle.c
M source/blender/blenkernel/intern/idprop.c
M source/blender/blenkernel/intern/image.c
M source/blender/blenkernel/intern/ipo.c
M source/blender/blenkernel/intern/lamp.c
M source/blender/blenkernel/intern/lattice.c
M source/blender/blenkernel/intern/library.c
M source/blender/blenkernel/intern/linestyle.c
M source/blender/blenkernel/intern/mask.c
M source/blender/blenkernel/intern/material.c
M source/blender/blenkernel/intern/mball.c
M source/blender/blenkernel/intern/mesh.c
M source/blender/blenkernel/intern/movieclip.c
M source/blender/blenkernel/intern/nla.c
M source/blender/blenkernel/intern/node.c
M source/blender/blenkernel/intern/object.c
M source/blender/blenkernel/intern/particle.c
M source/blender/blenkernel/intern/scene.c
M source/blender/blenkernel/intern/sequencer.c
M source/blender/blenkernel/intern/sound.c
M source/blender/blenkernel/intern/speaker.c
M source/blender/blenkernel/intern/texture.c
M source/blender/blenkernel/intern/world.c
M source/blender/collada/DocumentImporter.cpp
M source/blender/collada/MeshImporter.cpp
M source/blender/editors/curve/editcurve.c
M source/blender/editors/curve/editfont.c
M source/blender/editors/mesh/meshtools.c
M source/blender/editors/object/object_add.c
M source/blender/editors/object/object_edit.c
M source/blender/editors/object/object_relations.c
M source/blender/editors/physics/particle_object.c
M source/blender/editors/render/render_shading.c
M source/blender/editors/sound/sound_ops.c
M source/blender/editors/space_action/action_data.c
M source/blender/editors/space_clip/clip_ops.c
M source/blender/editors/space_image/image_ops.c
M source/blender/editors/space_logic/logic_window.c
M source/blender/editors/space_nla/nla_edit.c
M source/blender/editors/space_node/drawnode.c
M source/blender/editors/space_node/node_add.c
M source/blender/editors/space_node/node_edit.c
M source/blender/editors/space_node/node_templates.c
M source/blender/editors/space_outliner/outliner_tools.c
M source/blender/editors/space_sequencer/sequencer_edit.c
M source/blender/editors/transform/transform_generics.c
M source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
M source/blender/makesrna/intern/rna_object_force.c
M source/blender/makesrna/intern/rna_particle.c
M source/blender/makesrna/intern/rna_scene.c
M source/gameengine/Converter/KX_BlenderSceneConverter.cpp

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

diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index a5a29f6..3c83fbe 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 8010d34..2ddf014 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 fde2578..0d75724 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 95b65f5..201750d 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 46b74c5..73b1f0e 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 3e0bdbe..2235825 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 e66fa86..3069601 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 b12e16d..e8bfa27 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 f6c4263..3a15be5 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 4d83f8c..86d010f 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 ff30543..9dabe6b 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 he

@@ Diff output truncated at 10240 characters. @@
Bastien Montagne
2015-11-09 20:07:48 UTC
Permalink
Commit: f761ae8f116909f1d5c92398f8a4812a5fad8ca4
Author: Bastien Montagne
Date: Mon Nov 9 20:06:46 2015 +0100
Branches: master
https://developer.blender.org/rBf761ae8f116909f1d5c92398f8a4812a5fad8ca4

Rework a bit id_us_min, and make it assert on usercount error.

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

M source/blender/blenkernel/intern/library.c

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

diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 90cd950..fe5ddb5 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -184,12 +184,11 @@ void id_us_plus(ID *id)
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) {
- printf("ID user decrement error: %s\n", id->name);
+ const int limit = (id->flag & LIB_FAKEUSER) ? 1 : 0;
+ if (id->us <= limit) {
+ printf("ID user decrement error: %s (from '%s')\n", id->name, id->lib ? id->lib->filepath : "[Main]");
+ BLI_assert(0);
+ id->us = limit;
}
else {
id->us--;
Bastien Montagne
2015-11-09 20:07:50 UTC
Permalink
Commit: 9c6fe810a3cae2a5498f5760822b7a7e4a82bf4f
Author: Bastien Montagne
Date: Mon Nov 9 20:59:42 2015 +0100
Branches: master
https://developer.blender.org/rB9c6fe810a3cae2a5498f5760822b7a7e4a82bf4f

Fake user: add BKE_library helpers to set/clear that flag.

Since it also involves usercount manipulation, safer and cleaner to do it in BKE_library...

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

M source/blender/blenkernel/BKE_library.h
M source/blender/blenkernel/intern/brush.c
M source/blender/blenkernel/intern/library.c
M source/blender/blenkernel/intern/mask.c
M source/blender/blenkernel/intern/paint.c
M source/blender/blenloader/intern/readfile.c
M source/blender/editors/interface/interface_templates.c
M source/blender/editors/space_action/action_data.c
M source/blender/editors/space_outliner/outliner_tools.c
M source/blender/makesrna/intern/rna_ID.c
M source/blender/makesrna/intern/rna_main_api.c

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

diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h
index e11e949..e27198a 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -64,6 +64,8 @@ void BKE_library_filepath_set(struct Library *lib, const char *filepath);
void id_us_ensure_real(struct ID *id);
void id_us_plus(struct ID *id);
void id_us_min(struct ID *id);
+void id_fake_user_set(struct ID *id);
+void id_fake_user_clear(struct ID *id);

bool id_make_local(struct ID *id, bool test);
bool id_single_user(struct bContext *C, struct ID *id, struct PointerRNA *ptr, struct PropertyRNA *prop);
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 201750d..92ab4d7 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -136,7 +136,7 @@ void BKE_brush_init(Brush *brush)
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(brush, id));

/* enable fake user by default */
- brush->id.flag |= LIB_FAKEUSER;
+ id_fake_user_set(&brush->id);

brush_defaults(brush);

@@ -193,11 +193,8 @@ Brush *BKE_brush_copy(Brush *brush)
brushn->curve = curvemapping_copy(brush->curve);

/* enable fake user by default */
- if (!(brushn->id.flag & LIB_FAKEUSER)) {
- brushn->id.flag |= LIB_FAKEUSER;
- id_us_plus(&brushn->id);
- }
-
+ id_fake_user_set(&brush->id);
+
if (brush->id.lib) {
BKE_id_lib_local_paths(G.main, brush->id.lib, &brushn->id);
}
@@ -280,15 +277,11 @@ void BKE_brush_make_local(Brush *brush)
extern_local_brush(brush);

/* enable fake user by default */
- if (!(brush->id.flag & LIB_FAKEUSER)) {
- brush->id.flag |= LIB_FAKEUSER;
- id_us_plus(&brush->id);
- }
+ id_fake_user_set(&brush->id);
}
else if (is_local && is_lib) {
- Brush *brush_new = BKE_brush_copy(brush);
+ Brush *brush_new = BKE_brush_copy(brush); /* Ensures FAKE_USER is set */
brush_new->id.us = 1; /* only keep fake user */
- brush_new->id.flag |= LIB_FAKEUSER;

/* Remap paths of new ID using old library as base. */
BKE_id_lib_local_paths(bmain, brush->id.lib, &brush_new->id);
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index fe5ddb5..5091ab7 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -196,6 +196,22 @@ void id_us_min(ID *id)
}
}

+void id_fake_user_set(ID *id)
+{
+ if (id && !(id->flag & LIB_FAKEUSER)) {
+ id->flag |= LIB_FAKEUSER;
+ id_us_plus(id);
+ }
+}
+
+void id_fake_user_clear(ID *id)
+{
+ if (id && (id->flag & LIB_FAKEUSER)) {
+ id->flag &= ~LIB_FAKEUSER;
+ id_us_min(id);
+ }
+}
+
/* calls the appropriate make_local method for the block, unless test. Returns true
* if the block can be made local. */
bool id_make_local(ID *id, bool test)
@@ -1610,10 +1626,7 @@ void id_clear_lib_data(Main *bmain, ID *id)

BKE_id_lib_local_paths(bmain, id->lib, id);

- if (id->flag & LIB_FAKEUSER) {
- id->us--;
- id->flag &= ~LIB_FAKEUSER;
- }
+ id_fake_user_clear(id);

id->lib = NULL;
id->flag = LIB_LOCAL;
diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c
index b79c72a..cd26691 100644
--- a/source/blender/blenkernel/intern/mask.c
+++ b/source/blender/blenkernel/intern/mask.c
@@ -804,7 +804,7 @@ static Mask *mask_alloc(Main *bmain, const char *name)

mask = BKE_libblock_alloc(bmain, ID_MSK, name);

- mask->id.flag |= LIB_FAKEUSER;
+ id_fake_user_set(&mask->id);

return mask;
}
@@ -843,10 +843,7 @@ Mask *BKE_mask_copy_nolib(Mask *mask)
BKE_mask_layer_copy_list(&mask_new->masklayers, &mask->masklayers);

/* enable fake user by default */
- if (!(mask_new->id.flag & LIB_FAKEUSER)) {
- mask_new->id.flag |= LIB_FAKEUSER;
- id_us_plus(&mask_new->id);
- }
+ id_fake_user_set(&mask->id);

return mask_new;
}
@@ -862,10 +859,7 @@ Mask *BKE_mask_copy(Mask *mask)
BKE_mask_layer_copy_list(&mask_new->masklayers, &mask->masklayers);

/* enable fake user by default */
- if (!(mask_new->id.flag & LIB_FAKEUSER)) {
- mask_new->id.flag |= LIB_FAKEUSER;
- id_us_plus(&mask_new->id);
- }
+ id_fake_user_set(&mask->id);

if (mask->id.lib) {
BKE_id_lib_local_paths(G.main, mask->id.lib, &mask_new->id);
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 06844b0..1b6fc92 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -373,7 +373,7 @@ Palette *BKE_palette_add(Main *bmain, const char *name)
palette = BKE_libblock_alloc(bmain, ID_PAL, name);

/* enable fake user by default */
- palette->id.flag |= LIB_FAKEUSER;
+ id_fake_user_set(&palette->id);

return palette;
}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 9ebae18..73e13a7 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -7928,8 +7928,7 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID
/* clear first 8 bits */
id->flag = (id->flag & 0xFF00) | flag | LIB_NEED_LINK;
id->lib = main->curlib;
- if (id->flag & LIB_FAKEUSER) id->us= 1;
- else id->us = 0;
+ id->us = (id->flag & LIB_FAKEUSER) ? 1 : 0;
id->icon_id = 0;
id->flag &= ~(LIB_ID_RECALC | LIB_ID_RECALC_DATA | LIB_DOIT | LIB_MISSING);

diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 1238b88..c606dd6 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -275,7 +275,7 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event)

if (id && CTX_wm_window(C)->eventstate->shift) {
/* only way to force-remove data (on save) */
- id->flag &= ~LIB_FAKEUSER;
+ id_fake_user_clear(id);
id->us = 0;
}

diff --git a/source/blender/editors/space_action/action_data.c b/source/blender/editors/space_action/action_data.c
index 8ce126b..a3be779 100644
--- a/source/blender/editors/space_action/action_data.c
+++ b/source/blender/editors/space_action/action_data.c
@@ -581,10 +581,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;
- id_us_min(&act->id);
- }
+ id_fake_user_clear(&act->id);
}

/* If in Tweak Mode, don't unlink. Instead, this
diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c
index c0464c8..313a75f 100644
--- a/source/blender/editors/space_outliner/outliner_tools.c
+++ b/source/blender/editors/space_outliner/outliner_tools.c
@@ -421,10 +421,7 @@ static void id_fake_user_set_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeE
{
ID *id = tselem->id;

- if ((id) && ((id->flag & LIB_FAKEUSER) == 0)) {
- id->flag |= LIB_FAKEUSER;
- id_us_plus(id);
- }
+ id_fake_user_set(id);
}

static void id_fake_user_clear_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *UNUSED(te),
@@ -432,10 +429,7 @@ static void id_fake_user_clear_cb(bContext *UNUSED(C), Scene *UNUSED(scene), Tre
{
ID *id = tselem->id;

- if ((id) && (id->flag & LIB_FAKEUSER)) {
- id->flag &= ~LIB_FAKEUSER;
- id_us_min(id);
- }
+ id_fake_user_clear(id);
}

static void id_select_linked_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te),
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index 43ffc77..e1e892a 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -223,13 +223,11 @@ void rna_ID_fake_user_set(PointerRNA *ptr, int value)
{
ID *id = (ID *)ptr->data;

- if (value && !(id->flag & LIB_FAKEUSER)) {
- id->flag |= LIB_FAKEUSER;
- id_us_plus(id);
+ if (value) {
+ id_fake_user_set(id);
}
- else if (!value && (id->flag & LIB_FAKEUSER)) {
- id->flag &= ~LIB_FAKEUSER;
- id_us_min(id);
+ else {
+ id_fake_user_clear(id);
}
}

@@ -329,8 +327,8 @@ static void rna_ID_update_tag(ID *id, ReportList *reports, int flag)

static void rna_ID_user_clear(ID *id)
{
+ id_fake_user_clear(id);
id->us = 0; /* don't save */
- id->flag &= ~LIB_FAKEUSER;
}

static AnimData * rna_ID_animation_data_create(ID *id, Main *bmain)
diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c
index 057fed5..710ae97 100644
--- a/source/blender/makesrna/intern/rna_main_api.c
+++ b/source/blender/makesrna/intern/rna_main_api.c
@@ -639,8 +639,7 @@ static void rna_Main_armatures_remove(Main *bmain, ReportList *reports, PointerR
static bAction *rna_Main_actions_new(Main *bmain, const char *name)
{
bAction *act = add_empty_action(bmain, name);
- id_us_min(&act->id);
- act->id.flag &= ~LIB_FAKEUSER;
+ id_fake_user_clear(&act->id);
return act;
}
static void rna_Main_actions_remove(Main *bmain, ReportList *reports, PointerRNA *act_ptr)
Loading...