enter editmode when adding objects even if the object is not in an active layer,
authorCampbell Barton <ideasman42@gmail.com>
Thu, 5 Nov 2009 14:25:08 +0000 (14:25 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 5 Nov 2009 14:25:08 +0000 (14:25 +0000)
useful for python but in rare cases this also happens for users.

Active layer getting out of sync is an old bug but hard find when it happens.
This at least fixes segfaulting on adding objects.

source/blender/editors/include/ED_object.h
source/blender/editors/mesh/editmesh_add.c
source/blender/editors/object/object_add.c
source/blender/editors/object/object_edit.c

index 3d445016d9892d94143ec73212d66381376bde8c..b2d92869a2f3c5fc260e7a93476c4719c63a5293 100644 (file)
@@ -74,6 +74,7 @@ void ED_object_toggle_modes(struct bContext *C, int mode);
 #define EM_FREEUNDO            2
 #define EM_WAITCURSOR  4
 #define EM_DO_UNDO             8
+#define EM_IGNORE_LAYER        16
 void ED_object_exit_editmode(struct bContext *C, int flag);
 void ED_object_enter_editmode(struct bContext *C, int flag);
 
index 85c3558c2ef1cb32cdefb1f783d5185f1e8b8803..5905b2021ea7d186868093419ca5b041ed70dca9 100644 (file)
@@ -1317,9 +1317,8 @@ static void make_prim_ext(bContext *C, int view_align, int enter_editmode,
 
        if(obedit==NULL || obedit->type!=OB_MESH) {
                /* create editmode */
-               ED_object_add_type(C, OB_MESH, view_align, FALSE);
-               ED_object_enter_editmode(C, EM_DO_UNDO);
-               obedit= CTX_data_edit_object(C);
+               obedit= ED_object_add_type(C, OB_MESH, view_align, FALSE);
+               ED_object_enter_editmode(C, EM_DO_UNDO|EM_IGNORE_LAYER); /* rare cases the active layer is messed up */
                newob = 1;
        }
        else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
index 80426fd6a494a8c5f533f30641ce87dfff2c9cfb..016bc172410805a185f7de0ac920a230cd278c40 100644 (file)
@@ -196,7 +196,7 @@ Object *ED_object_add_type(bContext *C, int type, int view_align, int enter_edit
        DAG_scene_sort(scene);
 
        if(enter_editmode)
-               ED_object_enter_editmode(C, 0);
+               ED_object_enter_editmode(C, EM_IGNORE_LAYER);
 
        return ob;
 }
@@ -342,9 +342,8 @@ static int object_add_curve_exec(bContext *C, wmOperator *op)
        ED_object_add_generic_get_opts(op, &view_align, &enter_editmode);
        
        if(obedit==NULL || obedit->type!=OB_CURVE) {
-               ED_object_add_type(C, OB_CURVE, view_align, TRUE);
+               obedit= ED_object_add_type(C, OB_CURVE, view_align, TRUE);
                newob = 1;
-               obedit= CTX_data_edit_object(C);
 
                if(type & CU_PRIM_PATH)
                        ((Curve*)obedit->data)->flag |= CU_PATH|CU_3D;
@@ -427,12 +426,11 @@ static int object_add_surface_exec(bContext *C, wmOperator *op)
        ED_object_add_generic_get_opts(op, &view_align, &enter_editmode);
        
        if(obedit==NULL || obedit->type!=OB_SURF) {
-               ED_object_add_type(C, OB_SURF, view_align, TRUE);
+               obedit= ED_object_add_type(C, OB_SURF, view_align, TRUE);
                newob = 1;
        }
        else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
        
-       obedit= CTX_data_edit_object(C);
        nu= add_nurbs_primitive(C, RNA_enum_get(op->ptr, "type"), newob);
        editnurb= curve_get_editcurve(obedit);
        BLI_addtail(editnurb, nu);
@@ -488,12 +486,11 @@ static int object_metaball_add_exec(bContext *C, wmOperator *op)
        ED_object_add_generic_get_opts(op, &view_align, &enter_editmode);
        
        if(obedit==NULL || obedit->type!=OB_MBALL) {
-               ED_object_add_type(C, OB_MBALL, view_align, TRUE);
+               obedit= ED_object_add_type(C, OB_MBALL, view_align, TRUE);
                newob = 1;
        }
        else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
        
-       obedit= CTX_data_edit_object(C);
        elem= (MetaElem*)add_metaball_primitive(C, RNA_enum_get(op->ptr, "type"), newob);
        mball= (MetaBall*)obedit->data;
        BLI_addtail(mball->editelems, elem);
@@ -556,8 +553,7 @@ static int object_add_text_exec(bContext *C, wmOperator *op)
        if(obedit && obedit->type==OB_FONT)
                return OPERATOR_CANCELLED;
 
-       ED_object_add_type(C, OB_FONT, view_align, enter_editmode);
-       obedit= CTX_data_active_object(C);
+       obedit= ED_object_add_type(C, OB_FONT, view_align, enter_editmode);
        
        WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
        
@@ -593,9 +589,8 @@ static int object_armature_add_exec(bContext *C, wmOperator *op)
        ED_object_add_generic_get_opts(op, &view_align, &enter_editmode);
        
        if ((obedit==NULL) || (obedit->type != OB_ARMATURE)) {
-               ED_object_add_type(C, OB_ARMATURE, view_align, TRUE);
+               obedit= ED_object_add_type(C, OB_ARMATURE, view_align, TRUE);
                ED_object_enter_editmode(C, 0);
-               obedit= CTX_data_edit_object(C);
                newob = 1;
        }
        else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
index e659cd7067295a7821bebbb1d7fe3089257f386a..371d87260cdec72f0086f6b2fb2401a7178baefc 100644 (file)
@@ -371,25 +371,29 @@ void ED_object_exit_editmode(bContext *C, int flag)
 void ED_object_enter_editmode(bContext *C, int flag)
 {
        Scene *scene= CTX_data_scene(C);
-       Base *base= CTX_data_active_base(C);
+       Base *base= NULL;
        Object *ob;
        ScrArea *sa= CTX_wm_area(C);
        View3D *v3d= NULL;
        int ok= 0;
        
        if(scene->id.lib) return;
-       if(base==NULL) return;
        
        if(sa && sa->spacetype==SPACE_VIEW3D)
                v3d= sa->spacedata.first;
        
-       if(v3d && (base->lay & v3d->lay)==0) return;
-       else if(!v3d && (base->lay & scene->lay)==0) return;
+       if((flag & EM_IGNORE_LAYER)==0) {
+               if(v3d && (base->lay & v3d->lay)==0) return;
+               else if(!v3d && (base->lay & scene->lay)==0) return;
+               base= CTX_data_active_base(C); /* active layer checked here for view3d */
+       }
+       else {
+               base= scene->basact;
+       }
 
-       ob = base->object;
+       if (ELEM3(NULL, base, base->object, base->object->data)) return;
 
-       if(ob==NULL) return;
-       if(ob->data==NULL) return;
+       ob = base->object;
        
        if (object_data_is_libdata(ob)) {
                error_libdata();