- making local object data - Curve/Mesh/MBall lost references to linked materials.
- joining a linked mesh object into a local one lost the link.
As well as these reported bugs, checked all local functions for consistency/correctness and found other cases which would also fail.
- making local metaball didn't ensure unique ID name.
- make_local_armature() was missing check for object users - main body of code would never run.
- local particles didn't set the dupli-group or textures to extern.
checked all local functions for consistency/correctness.
struct Material *localize_material(struct Material *ma);
struct Material *give_node_material(struct Material *ma); /* returns node material or self */
void make_local_material(struct Material *ma);
+void extern_local_matarar(struct Material **matar, short totcol);
void automatname(struct Material *);
struct Mesh *add_mesh(const char *name);
struct Mesh *copy_mesh(struct Mesh *me);
void mesh_update_customdata_pointers(struct Mesh *me);
-void make_local_tface(struct Mesh *me);
void make_local_mesh(struct Mesh *me);
void boundbox_mesh(struct Mesh *me, float *loc, float *size);
void tex_space_mesh(struct Mesh *me);
struct Object *add_object(struct Scene *scene, int type);
struct Object *copy_object(struct Object *ob);
-void expand_local_object(struct Object *ob);
void make_local_object(struct Object *ob);
int object_is_libdata(struct Object *ob);
int object_data_is_libdata(struct Object *ob);
void make_local_action(bAction *act)
{
// Object *ob;
+ Main *bmain= G.main;
bAction *actn;
int local=0, lib=0;
if (act->id.us==1) {
act->id.lib= NULL;
act->id.flag= LIB_LOCAL;
- new_id(NULL, (ID *)act, NULL);
+ new_id(&bmain->action, (ID *)act, NULL);
return;
}
act->id.lib= NULL;
act->id.flag= LIB_LOCAL;
//make_local_action_channels(act);
- new_id(NULL, (ID *)act, NULL);
+ new_id(&bmain->action, (ID *)act, NULL);
}
else if(local && lib) {
actn= copy_action(act);
void make_local_armature(bArmature *arm)
{
+ Main *bmain= G.main;
int local=0, lib=0;
Object *ob;
- bArmature *newArm;
-
- if (arm->id.lib==NULL)
- return;
+
+ if (arm->id.lib==NULL) return;
if (arm->id.us==1) {
arm->id.lib= NULL;
arm->id.flag= LIB_LOCAL;
- new_id(NULL, (ID*)arm, NULL);
+ new_id(&bmain->armature, (ID*)arm, NULL);
return;
}
-
+
+ for(ob= bmain->object.first; ob && ELEM(0, lib, local); ob= ob->id.next) {
+ if(ob->data == arm) {
+ if(ob->id.lib) lib= 1;
+ else local= 1;
+ }
+ }
+
if(local && lib==0) {
arm->id.lib= NULL;
arm->id.flag= LIB_LOCAL;
- new_id(NULL, (ID *)arm, NULL);
+ new_id(&bmain->armature, (ID *)arm, NULL);
}
else if(local && lib) {
- newArm= copy_armature(arm);
- newArm->id.us= 0;
+ bArmature *armn= copy_armature(arm);
+ armn->id.us= 0;
- ob= G.main->object.first;
- while(ob) {
- if(ob->data==arm) {
-
+ for(ob= bmain->object.first; ob; ob= ob->id.next) {
+ if(ob->data == arm) {
if(ob->id.lib==NULL) {
- ob->data= newArm;
- newArm->id.us++;
+ ob->data= armn;
+ armn->id.us++;
arm->id.us--;
}
}
- ob= ob->id.next;
}
}
}
curvemapping_free(brush->curve);
}
+static void extern_local_brush(Brush *brush)
+{
+ id_lib_extern((ID *)brush->mtex.tex);
+}
+
void make_local_brush(Brush *brush)
{
+
/* - only lib users: do nothing
- * - only local users: set flag
- * - mixed: make copy
- */
-
- Brush *brushn;
+ * - only local users: set flag
+ * - mixed: make copy
+ */
+
+ Main *bmain= G.main;
Scene *scene;
int local= 0, lib= 0;
/* special case: ima always local immediately */
brush->clone.image->id.lib= NULL;
brush->clone.image->id.flag= LIB_LOCAL;
- new_id(NULL, (ID *)brush->clone.image, NULL);
+ new_id(&bmain->brush, (ID *)brush->clone.image, NULL);
+ extern_local_brush(brush);
}
- for(scene= G.main->scene.first; scene; scene=scene->id.next)
+ for(scene= bmain->scene.first; scene && ELEM(0, lib, local); scene=scene->id.next) {
if(paint_brush(&scene->toolsettings->imapaint.paint)==brush) {
if(scene->id.lib) lib= 1;
else local= 1;
}
+ }
if(local && lib==0) {
brush->id.lib= NULL;
brush->id.flag= LIB_LOCAL;
- new_id(NULL, (ID *)brush, NULL);
+ new_id(&bmain->brush, (ID *)brush, NULL);
+ extern_local_brush(brush);
/* enable fake user by default */
if (!(brush->id.flag & LIB_FAKEUSER)) {
}
}
else if(local && lib) {
- brushn= copy_brush(brush);
+ Brush *brushn= copy_brush(brush);
brushn->id.us= 1; /* only keep fake user */
brushn->id.flag |= LIB_FAKEUSER;
- for(scene= G.main->scene.first; scene; scene=scene->id.next)
- if(paint_brush(&scene->toolsettings->imapaint.paint)==brush)
+ for(scene= bmain->scene.first; scene; scene=scene->id.next) {
+ if(paint_brush(&scene->toolsettings->imapaint.paint)==brush) {
if(scene->id.lib==NULL) {
paint_brush_set(&scene->toolsettings->imapaint.paint, brushn);
brushn->id.us++;
brush->id.us--;
}
+ }
+ }
}
}
#include "BKE_key.h"
#include "BKE_library.h"
#include "BKE_main.h"
-#include "BKE_object.h"
+#include "BKE_object.h"
+#include "BKE_material.h"
#include "ED_curve.h"
return cun;
}
+static void extern_local_curve(Curve *cu)
+{
+ id_lib_extern((ID *)cu->vfont);
+ id_lib_extern((ID *)cu->vfontb);
+ id_lib_extern((ID *)cu->vfonti);
+ id_lib_extern((ID *)cu->vfontbi);
+
+ if(cu->mat) {
+ extern_local_matarar(cu->mat, cu->totcol);
+ }
+}
+
void make_local_curve(Curve *cu)
{
- Object *ob = NULL;
- Curve *cun;
+ Main *bmain= G.main;
+ Object *ob;
int local=0, lib=0;
/* - when there are only lib users: don't do
if(cu->id.lib==NULL) return;
- if(cu->vfont) cu->vfont->id.lib= NULL;
- if(cu->vfontb) cu->vfontb->id.lib= NULL;
- if(cu->vfonti) cu->vfonti->id.lib= NULL;
- if(cu->vfontbi) cu->vfontbi->id.lib= NULL;
-
if(cu->id.us==1) {
cu->id.lib= NULL;
cu->id.flag= LIB_LOCAL;
- new_id(NULL, (ID *)cu, NULL);
+
+ new_id(&bmain->curve, (ID *)cu, NULL);
+ extern_local_curve(cu);
return;
}
-
- ob= G.main->object.first;
- while(ob) {
- if(ob->data==cu) {
+
+ for(ob= bmain->object.first; ob && ELEM(0, lib, local); ob= ob->id.next) {
+ if(ob->data == cu) {
if(ob->id.lib) lib= 1;
else local= 1;
}
- ob= ob->id.next;
}
-
+
if(local && lib==0) {
cu->id.lib= NULL;
cu->id.flag= LIB_LOCAL;
- new_id(NULL, (ID *)cu, NULL);
+
+ new_id(&bmain->curve, (ID *)cu, NULL);
+ extern_local_curve(cu);
}
else if(local && lib) {
- cun= copy_curve(cu);
+ Curve *cun= copy_curve(cu);
cun->id.us= 0;
-
- ob= G.main->object.first;
- while(ob) {
+
+ for(ob= bmain->object.first; ob; ob= ob->id.next) {
if(ob->data==cu) {
-
if(ob->id.lib==NULL) {
ob->data= cun;
cun->id.us++;
cu->id.us--;
}
}
- ob= ob->id.next;
}
}
}
void make_local_lattice(Lattice *lt)
{
+ Main *bmain= G.main;
Object *ob;
- Lattice *ltn;
int local=0, lib=0;
/* - only lib users: do nothing
if(lt->id.us==1) {
lt->id.lib= NULL;
lt->id.flag= LIB_LOCAL;
- new_id(NULL, (ID *)lt, NULL);
+ new_id(&bmain->latt, (ID *)lt, NULL);
return;
}
- ob= G.main->object.first;
- while(ob) {
+ for(ob= bmain->object.first; ob && ELEM(0, lib, local); ob= ob->id.next) {
if(ob->data==lt) {
if(ob->id.lib) lib= 1;
else local= 1;
}
- ob= ob->id.next;
}
if(local && lib==0) {
lt->id.lib= NULL;
lt->id.flag= LIB_LOCAL;
- new_id(NULL, (ID *)lt, NULL);
+ new_id(&bmain->latt, (ID *)lt, NULL);
}
else if(local && lib) {
- ltn= copy_lattice(lt);
+ Lattice *ltn= copy_lattice(lt);
ltn->id.us= 0;
-
- ob= G.main->object.first;
- while(ob) {
+
+ for(ob= bmain->object.first; ob; ob= ob->id.next) {
if(ob->data==lt) {
-
if(ob->id.lib==NULL) {
ob->data= ltn;
ltn->id.us++;
lt->id.us--;
}
}
- ob= ob->id.next;
}
}
}
return man;
}
+static void extern_local_material(Material *ma)
+{
+ int i;
+ for(i=0; i < MAX_MTEX; i++) {
+ if(ma->mtex[i]) id_lib_extern((ID *)ma->mtex[i]->tex);
+ }
+}
+
void make_local_material(Material *ma)
{
Main *bmain= G.main;
if(ma->id.us==1) {
ma->id.lib= NULL;
ma->id.flag= LIB_LOCAL;
- new_id(NULL, (ID *)ma, NULL);
- for(a=0; a<MAX_MTEX; a++) {
- if(ma->mtex[a]) id_lib_extern((ID *)ma->mtex[a]->tex);
- }
-
+
+ new_id(&bmain->mat, (ID *)ma, NULL);
+ extern_local_material(ma);
return;
}
if(local && lib==0) {
ma->id.lib= NULL;
ma->id.flag= LIB_LOCAL;
-
- for(a=0; a<MAX_MTEX; a++) {
- if(ma->mtex[a]) id_lib_extern((ID *)ma->mtex[a]->tex);
- }
-
- new_id(NULL, (ID *)ma, NULL);
+
+ new_id(&bmain->mat, (ID *)ma, NULL);
+ extern_local_material(ma);
}
else if(local && lib) {
}
}
+/* for curve, mball, mesh types */
+void extern_local_matarar(struct Material **matar, short totcol)
+{
+ short i;
+ for(i= 0; i < totcol; i++) {
+ id_lib_extern((ID *)matar[i]);
+ }
+}
+
Material ***give_matarar(Object *ob)
{
Mesh *me;
#include "BKE_displist.h"
#include "BKE_mball.h"
#include "BKE_object.h"
+#include "BKE_material.h"
/* Global variables */
return mbn;
}
+static void extern_local_mball(MetaBall *mb)
+{
+ if(mb->mat) {
+ extern_local_matarar(mb->mat, mb->totcol);
+ }
+}
+
void make_local_mball(MetaBall *mb)
{
+ Main *bmain= G.main;
Object *ob;
- MetaBall *mbn;
int local=0, lib=0;
/* - only lib users: do nothing
if(mb->id.us==1) {
mb->id.lib= NULL;
mb->id.flag= LIB_LOCAL;
+ new_id(&bmain->mball, (ID *)mb, NULL);
+ extern_local_mball(mb);
+
return;
}
-
- ob= G.main->object.first;
- while(ob) {
- if(ob->data==mb) {
+
+ for(ob= G.main->object.first; ob && ELEM(0, lib, local); ob= ob->id.next) {
+ if(ob->data == mb) {
if(ob->id.lib) lib= 1;
else local= 1;
}
- ob= ob->id.next;
}
if(local && lib==0) {
mb->id.lib= NULL;
mb->id.flag= LIB_LOCAL;
+
+ new_id(&bmain->mball, (ID *)mb, NULL);
+ extern_local_mball(mb);
}
else if(local && lib) {
- mbn= copy_mball(mb);
+ MetaBall *mbn= copy_mball(mb);
mbn->id.us= 0;
-
- ob= G.main->object.first;
- while(ob) {
- if(ob->data==mb) {
-
+
+ for(ob= G.main->object.first; ob; ob= ob->id.next) {
+ if(ob->data == mb) {
if(ob->id.lib==NULL) {
ob->data= mbn;
mbn->id.us++;
mb->id.us--;
}
}
- ob= ob->id.next;
}
}
}
return men;
}
-void make_local_tface(Mesh *me)
+static void make_local_tface(Main *bmain, Mesh *me)
{
MTFace *tface;
Image *ima;
if(ima->id.lib) {
ima->id.lib= NULL;
ima->id.flag= LIB_LOCAL;
- new_id(NULL, (ID *)ima, NULL);
+ new_id(&bmain->image, (ID *)ima, NULL);
}
}
}
}
}
+static void expand_local_mesh(Main *bmain, Mesh *me)
+{
+ id_lib_extern((ID *)me->texcomesh);
+
+ if(me->mtface) {
+ /* why is this an exception? - should not really make local when extern'ing - campbell */
+ make_local_tface(bmain, me);
+ }
+
+ if(me->mat) {
+ extern_local_matarar(me->mat, me->totcol);
+ }
+}
+
void make_local_mesh(Mesh *me)
{
Main *bmain= G.main;
Object *ob;
- Mesh *men;
int local=0, lib=0;
/* - only lib users: do nothing
- * - only local users: set flag
- * - mixed: make copy
- */
-
+ * - only local users: set flag
+ * - mixed: make copy
+ */
+
if(me->id.lib==NULL) return;
if(me->id.us==1) {
me->id.lib= NULL;
me->id.flag= LIB_LOCAL;
- new_id(NULL, (ID *)me, NULL);
-
- if(me->mtface) make_local_tface(me);
-
+
+ new_id(&bmain->mesh, (ID *)me, NULL);
+ expand_local_mesh(bmain, me);
return;
}
-
- ob= bmain->object.first;
- while(ob) {
- if( me==get_mesh(ob) ) {
+
+ for(ob= bmain->object.first; ob && ELEM(0, lib, local); ob= ob->id.next) {
+ if(me == ob->data) {
if(ob->id.lib) lib= 1;
else local= 1;
}
- ob= ob->id.next;
}
-
+
if(local && lib==0) {
me->id.lib= NULL;
me->id.flag= LIB_LOCAL;
- new_id(NULL, (ID *)me, NULL);
-
- if(me->mtface) make_local_tface(me);
-
+
+ new_id(&bmain->mesh, (ID *)me, NULL);
+ expand_local_mesh(bmain, me);
}
else if(local && lib) {
- men= copy_mesh(me);
+ Mesh *men= copy_mesh(me);
men->id.us= 0;
-
- ob= bmain->object.first;
- while(ob) {
- if( me==get_mesh(ob) ) {
+
+ for(ob= bmain->object.first; ob; ob= ob->id.next) {
+ if(me == ob->data) {
if(ob->id.lib==NULL) {
set_mesh(ob, men);
}
}
- ob= ob->id.next;
}
}
}
#include "BKE_scene.h"
#include "BKE_sequencer.h"
#include "BKE_softbody.h"
+#include "BKE_material.h"
#include "LBM_fluidsim.h"
{
Main *bmain= G.main;
Object *ob;
- Camera *camn;
int local=0, lib=0;
/* - only lib users: do nothing
- * - only local users: set flag
- * - mixed: make copy
- */
+ * - only local users: set flag
+ * - mixed: make copy
+ */
if(cam->id.lib==NULL) return;
if(cam->id.us==1) {
cam->id.lib= NULL;
cam->id.flag= LIB_LOCAL;
- new_id(NULL, (ID *)cam, NULL);
+ new_id(&bmain->camera, (ID *)cam, NULL);
return;
}
- ob= bmain->object.first;
- while(ob) {
+ for(ob= bmain->object.first; ob && ELEM(0, lib, local); ob= ob->id.next) {
if(ob->data==cam) {
if(ob->id.lib) lib= 1;
else local= 1;
}
- ob= ob->id.next;
}
if(local && lib==0) {
cam->id.lib= NULL;
cam->id.flag= LIB_LOCAL;
- new_id(NULL, (ID *)cam, NULL);
+ new_id(&bmain->camera, (ID *)cam, NULL);
}
else if(local && lib) {
- camn= copy_camera(cam);
+ Camera *camn= copy_camera(cam);
camn->id.us= 0;
- ob= bmain->object.first;
- while(ob) {
- if(ob->data==cam) {
-
+ for(ob= bmain->object.first; ob; ob= ob->id.next) {
+ if(ob->data == cam) {
if(ob->id.lib==NULL) {
ob->data= camn;
camn->id.us++;
cam->id.us--;
}
}
- ob= ob->id.next;
}
}
}
if(la->id.us==1) {
la->id.lib= NULL;
la->id.flag= LIB_LOCAL;
- new_id(NULL, (ID *)la, NULL);
+ new_id(&bmain->lamp, (ID *)la, NULL);
return;
}
if(local && lib==0) {
la->id.lib= NULL;
la->id.flag= LIB_LOCAL;
- new_id(NULL, (ID *)la, NULL);
+ new_id(&bmain->lamp, (ID *)la, NULL);
}
else if(local && lib) {
lan= copy_lamp(la);
return obn;
}
-void expand_local_object(Object *ob)
+static void extern_local_object(Object *ob)
{
//bActionStrip *strip;
ParticleSystem *psys;
- int a;
#if 0 // XXX old animation system
id_lib_extern((ID *)ob->action);
#endif // XXX old animation system
id_lib_extern((ID *)ob->data);
id_lib_extern((ID *)ob->dup_group);
-
- for(a=0; a<ob->totcol; a++) {
- id_lib_extern((ID *)ob->mat[a]);
- }
+ id_lib_extern((ID *)ob->poselib);
+ id_lib_extern((ID *)ob->gpd);
+
+ extern_local_matarar(ob->mat, ob->totcol);
+
#if 0 // XXX old animation system
for (strip=ob->nlastrips.first; strip; strip=strip->next) {
id_lib_extern((ID *)strip->act);
void make_local_object(Object *ob)
{
Main *bmain= G.main;
- Object *obn;
Scene *sce;
Base *base;
int local=0, lib=0;
/* - only lib users: do nothing
- * - only local users: set flag
- * - mixed: make copy
- */
-
+ * - only local users: set flag
+ * - mixed: make copy
+ */
+
if(ob->id.lib==NULL) return;
ob->proxy= ob->proxy_from= NULL;
if(ob->id.us==1) {
ob->id.lib= NULL;
ob->id.flag= LIB_LOCAL;
- new_id(NULL, (ID *)ob, NULL);
-
+ new_id(&bmain->object, (ID *)ob, NULL);
}
else {
- sce= bmain->scene.first;
- while(sce) {
- base= sce->base.first;
- while(base) {
- if(base->object==ob) {
- if(sce->id.lib) lib++;
- else local++;
- break;
- }
- base= base->next;
+ for(sce= bmain->scene.first; sce && ELEM(0, lib, local); sce= sce->id.next) {
+ if(object_in_scene(ob, sce)) {
+ if(sce->id.lib) lib= 1;
+ else local= 1;
}
- sce= sce->id.next;
}
-
+
if(local && lib==0) {
ob->id.lib= NULL;
ob->id.flag= LIB_LOCAL;
- new_id(NULL, (ID *)ob, NULL);
+ new_id(&bmain->object, (ID *)ob, NULL);
}
else if(local && lib) {
- obn= copy_object(ob);
+ Object *obn= copy_object(ob);
obn->id.us= 0;
sce= bmain->scene.first;
}
}
- expand_local_object(ob);
+ extern_local_object(ob);
}
/*
return partn;
}
+static void expand_local_particlesettings(ParticleSettings *part)
+{
+ int i;
+ id_lib_extern((ID *)part->dup_group);
+
+ for(i=0; i<MAX_MTEX; i++) {
+ if(part->mtex[i]) id_lib_extern((ID *)part->mtex[i]->tex);
+ }
+}
+
void make_local_particlesettings(ParticleSettings *part)
{
+ Main *bmain= G.main;
Object *ob;
- ParticleSettings *par;
int local=0, lib=0;
/* - only lib users: do nothing
- * - only local users: set flag
- * - mixed: make copy
- */
+ * - only local users: set flag
+ * - mixed: make copy
+ */
if(part->id.lib==0) return;
if(part->id.us==1) {
part->id.lib= 0;
part->id.flag= LIB_LOCAL;
- new_id(0, (ID *)part, 0);
+ new_id(&bmain->particle, (ID *)part, 0);
+ expand_local_particlesettings(part);
return;
}
-
+
/* test objects */
- ob= G.main->object.first;
- while(ob) {
+ for(ob= bmain->object.first; ob && ELEM(0, lib, local); ob= ob->id.next) {
ParticleSystem *psys=ob->particlesystem.first;
for(; psys; psys=psys->next){
if(psys->part==part) {
else local= 1;
}
}
- ob= ob->id.next;
}
if(local && lib==0) {
part->id.lib= 0;
part->id.flag= LIB_LOCAL;
- new_id(0, (ID *)part, 0);
+ new_id(&bmain->particle, (ID *)part, 0);
+ expand_local_particlesettings(part);
}
else if(local && lib) {
-
- par= psys_copy_settings(part);
- par->id.us= 0;
+ ParticleSettings *partn= psys_copy_settings(part);
+ partn->id.us= 0;
/* do objects */
- ob= G.main->object.first;
- while(ob) {
- ParticleSystem *psys=ob->particlesystem.first;
- for(; psys; psys=psys->next){
+ for(ob= bmain->object.first; ob; ob= ob->id.next) {
+ ParticleSystem *psys;
+ for(psys= ob->particlesystem.first; psys; psys=psys->next){
if(psys->part==part && ob->id.lib==0) {
- psys->part= par;
- par->id.us++;
+ psys->part= partn;
+ partn->id.us++;
part->id.us--;
}
}
- ob= ob->id.next;
}
}
}
if(tex->ima) {
tex->ima->id.lib= NULL;
tex->ima->id.flag= LIB_LOCAL;
- new_id(NULL, (ID *)tex->ima, NULL);
+ new_id(&bmain->image, (ID *)tex->ima, NULL);
}
if(tex->id.us==1) {
tex->id.lib= NULL;
tex->id.flag= LIB_LOCAL;
- new_id(NULL, (ID *)tex, NULL);
+ new_id(&bmain->tex, (ID *)tex, NULL);
return;
}
if(local && lib==0) {
tex->id.lib= NULL;
tex->id.flag= LIB_LOCAL;
- new_id(NULL, (ID *)tex, NULL);
+ new_id(&bmain->tex, (ID *)tex, NULL);
}
else if(local && lib) {
texn= copy_texture(tex);
#include "DNA_scene_types.h"
#include "DNA_texture_types.h"
+#include "BLI_utildefines.h"
+
#include "BKE_world.h"
#include "BKE_library.h"
#include "BKE_animsys.h"
{
Main *bmain= G.main;
Scene *sce;
- World *wrldn;
int local=0, lib=0;
/* - only lib users: do nothing
return;
}
- sce= bmain->scene.first;
- while(sce) {
- if(sce->world==wrld) {
+ for(sce= bmain->scene.first; sce && ELEM(0, lib, local); sce= sce->id.next) {
+ if(sce->world == wrld) {
if(sce->id.lib) lib= 1;
else local= 1;
}
- sce= sce->id.next;
}
-
+
if(local && lib==0) {
wrld->id.lib= NULL;
wrld->id.flag= LIB_LOCAL;
new_id(NULL, (ID *)wrld, NULL);
}
else if(local && lib) {
- wrldn= copy_world(wrld);
+ World *wrldn= copy_world(wrld);
wrldn->id.us= 0;
- sce= bmain->scene.first;
- while(sce) {
- if(sce->world==wrld) {
+ for(sce= bmain->scene.first; sce; sce= sce->id.next) {
+ if(sce->world == wrld) {
if(sce->id.lib==NULL) {
sce->world= wrldn;
wrldn->id.us++;
wrld->id.us--;
}
}
- sce= sce->id.next;
}
}
}
}
if(b==totcol) {
matar[b]= ma;
- if(ma)
- ma->id.us++;
+ if(ma) {
+ id_us_plus(&ma->id);
+ }
totcol++;
}
if(totcol>=MAXMAT-1)