group refcount checking was inconsistent.
authorCampbell Barton <ideasman42@gmail.com>
Tue, 13 Jul 2010 16:53:17 +0000 (16:53 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 13 Jul 2010 16:53:17 +0000 (16:53 +0000)
- if a group has one or more objects in it, it gets a refcount of 1 on load (unchanged from before)
- dupli-groups, and materials no longer add/remove a reference.
- now groups are only freed when they contain no objects or when manually unlinked.

source/blender/blenkernel/intern/anim.c
source/blender/blenkernel/intern/material.c
source/blender/blenkernel/intern/object.c
source/blender/editors/object/object_add.c
source/blender/editors/object/object_edit.c
source/blender/editors/object/object_relations.c
source/blender/editors/space_outliner/outliner.c
source/blender/makesrna/intern/rna_main_api.c

index fa0ddc5f1d3df2b6d4b926cf5edf95b81e5f2fc0..157c0743c500851f8215f4f21d405b6d86dd1b1a 100644 (file)
@@ -741,7 +741,7 @@ static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int level, i
 
                        if(go->ob->transflag & OB_DUPLI) {
                                copy_m4_m4(dob->ob->obmat, dob->mat);
-                               object_duplilist_recursive((ID *)group, scene, go->ob, lb, ob->obmat, level+1, animated);
+                               object_duplilist_recursive(&group->id, scene, go->ob, lb, ob->obmat, level+1, animated);
                                copy_m4_m4(dob->ob->obmat, dob->omat);
                        }
                }
index 3b6a10c0872a07e742994291d1dedd38c623030f..11c96e9a3470cb5a57ffe54de66e15710c231a2d 100644 (file)
@@ -210,7 +210,7 @@ Material *copy_material(Material *ma)
 #if 0 // XXX old animation system
        id_us_plus((ID *)man->ipo);
 #endif // XXX old animation system
-       id_us_plus((ID *)man->group);
+       id_lib_extern((ID *)man->group);
        
        for(a=0; a<MAX_MTEX; a++) {
                if(ma->mtex[a]) {
index 6d264b3fed245bc50c4f5ff001e7f169e8815b0c..012b38570dade5b53e6397133bb9f7450ecfcbd8 100644 (file)
@@ -283,7 +283,6 @@ void free_object(Object *ob)
        ob->path= 0;
        if(ob->adt) BKE_free_animdata((ID *)ob);
        if(ob->poselib) ob->poselib->id.us--;
-       if(ob->dup_group) ob->dup_group->id.us--;
        if(ob->gpd) ob->gpd->id.us--;
        if(ob->defbase.first)
                BLI_freelistN(&ob->defbase);
@@ -1320,7 +1319,7 @@ Object *copy_object(Object *ob)
 
        /* increase user numbers */
        id_us_plus((ID *)obn->data);
-       id_us_plus((ID *)obn->dup_group);
+       id_lib_extern((ID *)obn->dup_group);
        
 
        for(a=0; a<obn->totcol; a++) id_us_plus((ID *)obn->mat[a]);
index 757c167c4966cb16b454e6cf086ebc663c751f89..2299207eaa92116f074f4bef3928a65c3e0b4e21 100644 (file)
@@ -754,8 +754,7 @@ static int group_instance_add_exec(bContext *C, wmOperator *op)
                rename_id(&ob->id, group->id.name+2);
                ob->dup_group= group;
                ob->transflag |= OB_DUPLIGROUP;
-               id_us_plus(&group->id);
-
+               id_lib_extern(&group->id);
 
                WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
 
index d3226b1adf4f6c28c7c9aab5ac2875d8f1e9f5aa..5fe09f0083e9e0eb101b8cf24bb4cb8f91602cbc 100644 (file)
@@ -1408,7 +1408,7 @@ void copy_attr(Scene *scene, View3D *v3d, short event)
 
                                        base->object->dup_group= ob->dup_group;
                                        if(ob->dup_group)
-                                               id_us_plus((ID *)ob->dup_group);
+                                               id_lib_extern(&ob->dup_group->id);
                                }
                                else if(event==7) {     /* mass */
                                        base->object->mass= ob->mass;
index fbc6075796ce6dfbe70abac740f883dd4e9201af..8d488eeabacc40b6c936e5e175757ff6afee3823 100644 (file)
@@ -1250,10 +1250,9 @@ static int make_links_data_exec(bContext *C, wmOperator *op)
                                        BKE_copy_animdata_id((ID *)obt->data, (ID *)ob->data);
                                        break;
                                case MAKE_LINKS_DUPLIGROUP:
-                                       if(ob->dup_group) ob->dup_group->id.us--;
                                        obt->dup_group= ob->dup_group;
                                        if(obt->dup_group) {
-                                               id_us_plus((ID *)obt->dup_group);
+                                               id_lib_extern(&obt->dup_group->id);
                                                obt->transflag |= OB_DUPLIGROUP;
                                        }
                                        break;
index 794c700f8ceeed045f048f2e952b5833ac7fa345..95e2cb920fc5e9317e8166345fba1ebcbb1f2761 100644 (file)
@@ -1411,7 +1411,7 @@ static void outliner_build_tree(Main *mainvar, Scene *scene, SpaceOops *soops)
                GroupObject *go;
                
                for(group= mainvar->group.first; group; group= group->id.next) {
-                       if(group->id.us) {
+                       if(group->gobject.first) {
                                te= outliner_add_element(soops, &soops->tree, group, NULL, 0, 0);
                                tselem= TREESTORE(te);
                                
@@ -3124,7 +3124,6 @@ static void unlink_group_cb(bContext *C, Scene *scene, TreeElement *te, TreeStor
                if( GS(tsep->id->name)==ID_OB) {
                        Object *ob= (Object *)tsep->id;
                        ob->dup_group= NULL;
-                       group->id.us--;
                }
        }
        else {
index 6c74ff2fefa4ab28449d4b8bddbb09127607bfd3..49359e03985cdd84712b264f295a18e94dfabc2c 100644 (file)
@@ -397,7 +397,6 @@ Group *rna_Main_groups_new(Main *bmain, char* name)
 void rna_Main_groups_remove(Main *bmain, ReportList *reports, Group *group)
 {
        unlink_group(group);
-       group->id.us= 0;
        free_libblock(&bmain->group, group);
        /* XXX python now has invalid pointer? */
 }