fix for crashes caused by mixups when adding objects when incompatible object types were already in editmode.

This commit is contained in:
Campbell Barton 2012-09-23 07:18:50 +00:00
parent 7d1a36f8f4
commit c574419049
6 changed files with 33 additions and 52 deletions

@ -6191,10 +6191,9 @@ static const char *get_surf_defname(int type)
}
Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newob)
Nurb *add_nurbs_primitive(bContext *C, Object *obedit, float mat[4][4], int type, int newob)
{
static int xzproj = 0; /* this function calls itself... */
Object *obedit = CTX_data_edit_object(C);
ListBase *editnurb = object_editcurve_get(obedit);
View3D *v3d = CTX_wm_view3d(C);
RegionView3D *rv3d = ED_view3d_context_rv3d(C);
@ -6431,7 +6430,7 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newob)
break;
case CU_PRIM_TUBE: /* Cylinder */
if (cutype == CU_NURBS) {
nu = add_nurbs_primitive(C, mat, CU_NURBS | CU_PRIM_CIRCLE, 0); /* circle */
nu = add_nurbs_primitive(C, obedit, mat, CU_NURBS | CU_PRIM_CIRCLE, 0); /* circle */
nu->resolu = cu->resolu;
nu->flag = CU_SMOOTH;
BLI_addtail(editnurb, nu); /* temporal for extrude and translate */
@ -6510,7 +6509,7 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newob)
float tmp_vec[3] = {0.f, 0.f, 1.f};
xzproj = 1;
nu = add_nurbs_primitive(C, mat, CU_NURBS | CU_PRIM_CIRCLE, 0); /* circle */
nu = add_nurbs_primitive(C, obedit, mat, CU_NURBS | CU_PRIM_CIRCLE, 0); /* circle */
xzproj = 0;
nu->resolu = cu->resolu;
nu->resolv = cu->resolv;
@ -6607,7 +6606,7 @@ static int curvesurf_prim_add(bContext *C, wmOperator *op, int type, int isSurf)
ED_object_new_primitive_matrix(C, obedit, loc, rot, mat);
nu = add_nurbs_primitive(C, mat, type, newob);
nu = add_nurbs_primitive(C, obedit, mat, type, newob);
editnurb = object_editcurve_get(obedit);
BLI_addtail(editnurb, nu);

@ -67,7 +67,7 @@ void BKE_curve_editNurb_free(struct Curve *cu);
int mouse_nurb(struct bContext *C, const int mval[2], int extend, int deselect, int toggle);
struct Nurb *add_nurbs_primitive(struct bContext *C, float mat[4][4], int type, int newob);
struct Nurb *add_nurbs_primitive(struct bContext *C, struct Object *obedit, float mat[4][4], int type, int newob);
int isNurbsel(struct Nurb *nu);
void ED_nurb_set_spline_type(struct Nurb *nu, int type);

@ -38,7 +38,7 @@ struct wmKeyConfig;
void ED_operatortypes_metaball(void);
void ED_keymap_metaball(struct wmKeyConfig *keyconf);
struct MetaElem *add_metaball_primitive(struct bContext *C, float mat[4][4], int type, int newname);
struct MetaElem *add_metaball_primitive(struct bContext *C, struct Object *obedit, float mat[4][4], int type, int newname);
int mouse_mball(struct bContext *C, const int mval[2], int extend, int deselect, int toggle);

@ -55,9 +55,9 @@
/* ********* add primitive operators ************* */
static void make_prim_init(bContext *C, const char *idname,
float *dia, float mat[][4],
int *state, const float loc[3], const float rot[3], const unsigned int layer)
static Object *make_prim_init(bContext *C, const char *idname,
float *dia, float mat[][4],
int *state, const float loc[3], const float rot[3], const unsigned int layer)
{
Object *obedit = CTX_data_edit_object(C);
@ -74,11 +74,12 @@ static void make_prim_init(bContext *C, const char *idname,
}
*dia = ED_object_new_primitive_matrix(C, obedit, loc, rot, mat);
return obedit;
}
static void make_prim_finish(bContext *C, int *state, int enter_editmode)
static void make_prim_finish(bContext *C, Object *obedit, int *state, int enter_editmode)
{
Object *obedit = CTX_data_edit_object(C);
BMEditMesh *em = BMEdit_FromObject(obedit);
/* Primitive has all verts selected, use vert select flush
@ -104,9 +105,7 @@ static int add_primitive_plane_exec(bContext *C, wmOperator *op)
unsigned int layer;
ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL);
make_prim_init(C, "Plane", &dia, mat, &state, loc, rot, layer);
obedit = CTX_data_edit_object(C);
obedit = make_prim_init(C, "Plane", &dia, mat, &state, loc, rot, layer);
em = BMEdit_FromObject(obedit);
if (!EDBM_op_call_and_selectf(em, op, "vertout",
@ -115,7 +114,7 @@ static int add_primitive_plane_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
make_prim_finish(C, &state, enter_editmode);
make_prim_finish(C, obedit, &state, enter_editmode);
return OPERATOR_FINISHED;
}
@ -148,9 +147,7 @@ static int add_primitive_cube_exec(bContext *C, wmOperator *op)
unsigned int layer;
ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL);
make_prim_init(C, "Cube", &dia, mat, &state, loc, rot, layer);
obedit = CTX_data_edit_object(C);
obedit = make_prim_init(C, "Cube", &dia, mat, &state, loc, rot, layer);
em = BMEdit_FromObject(obedit);
if (!EDBM_op_call_and_selectf(em, op, "vertout", "create_cube mat=%m4 size=%f", mat, dia * 2.0f)) {
@ -158,7 +155,7 @@ static int add_primitive_cube_exec(bContext *C, wmOperator *op)
}
/* BMESH_TODO make plane side this: M_SQRT2 - plane (diameter of 1.41 makes it unit size) */
make_prim_finish(C, &state, enter_editmode);
make_prim_finish(C, obedit, &state, enter_editmode);
return OPERATOR_FINISHED;
}
@ -200,9 +197,7 @@ static int add_primitive_circle_exec(bContext *C, wmOperator *op)
cap_tri = (cap_end == 2);
ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL);
make_prim_init(C, "Circle", &dia, mat, &state, loc, rot, layer);
obedit = CTX_data_edit_object(C);
obedit = make_prim_init(C, "Circle", &dia, mat, &state, loc, rot, layer);
em = BMEdit_FromObject(obedit);
if (!EDBM_op_call_and_selectf(em, op, "vertout",
@ -213,7 +208,7 @@ static int add_primitive_circle_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
make_prim_finish(C, &state, enter_editmode);
make_prim_finish(C, obedit, &state, enter_editmode);
return OPERATOR_FINISHED;
}
@ -257,9 +252,7 @@ static int add_primitive_cylinder_exec(bContext *C, wmOperator *op)
cap_tri = (cap_end == 2);
ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL);
make_prim_init(C, "Cylinder", &dia, mat, &state, loc, rot, layer);
obedit = CTX_data_edit_object(C);
obedit = make_prim_init(C, "Cylinder", &dia, mat, &state, loc, rot, layer);
em = BMEdit_FromObject(obedit);
if (!EDBM_op_call_and_selectf(
@ -274,7 +267,7 @@ static int add_primitive_cylinder_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
make_prim_finish(C, &state, enter_editmode);
make_prim_finish(C, obedit, &state, enter_editmode);
return OPERATOR_FINISHED;
}
@ -320,9 +313,7 @@ static int add_primitive_cone_exec(bContext *C, wmOperator *op)
cap_tri = (cap_end == 2);
ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL);
make_prim_init(C, "Cone", &dia, mat, &state, loc, rot, layer);
obedit = CTX_data_edit_object(C);
obedit = make_prim_init(C, "Cone", &dia, mat, &state, loc, rot, layer);
em = BMEdit_FromObject(obedit);
if (!EDBM_op_call_and_selectf(
@ -334,7 +325,7 @@ static int add_primitive_cone_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
make_prim_finish(C, &state, enter_editmode);
make_prim_finish(C, obedit, &state, enter_editmode);
return OPERATOR_FINISHED;
}
@ -379,9 +370,7 @@ static int add_primitive_grid_exec(bContext *C, wmOperator *op)
unsigned int layer;
ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL);
make_prim_init(C, "Grid", &dia, mat, &state, loc, rot, layer);
obedit = CTX_data_edit_object(C);
obedit = make_prim_init(C, "Grid", &dia, mat, &state, loc, rot, layer);
em = BMEdit_FromObject(obedit);
if (!EDBM_op_call_and_selectf(em, op, "vertout",
@ -393,7 +382,7 @@ static int add_primitive_grid_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
make_prim_finish(C, &state, enter_editmode);
make_prim_finish(C, obedit, &state, enter_editmode);
return OPERATOR_FINISHED;
}
@ -436,16 +425,14 @@ static int add_primitive_monkey_exec(bContext *C, wmOperator *op)
if (!view_aligned)
rot[0] += (float)M_PI / 2.0f;
make_prim_init(C, "Monkey", &dia, mat, &state, loc, rot, layer);
obedit = CTX_data_edit_object(C);
obedit = make_prim_init(C, "Monkey", &dia, mat, &state, loc, rot, layer);
em = BMEdit_FromObject(obedit);
if (!EDBM_op_call_and_selectf(em, op, "vertout", "create_monkey mat=%m4", mat)) {
return OPERATOR_CANCELLED;
}
make_prim_finish(C, &state, enter_editmode);
make_prim_finish(C, obedit, &state, enter_editmode);
return OPERATOR_FINISHED;
}
@ -477,9 +464,7 @@ static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op)
unsigned int layer;
ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL);
make_prim_init(C, "Sphere", &dia, mat, &state, loc, rot, layer);
obedit = CTX_data_edit_object(C);
obedit = make_prim_init(C, "Sphere", &dia, mat, &state, loc, rot, layer);
em = BMEdit_FromObject(obedit);
if (!EDBM_op_call_and_selectf(em, op, "vertout",
@ -490,7 +475,7 @@ static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
make_prim_finish(C, &state, enter_editmode);
make_prim_finish(C, obedit, &state, enter_editmode);
return OPERATOR_FINISHED;
}
@ -531,9 +516,7 @@ static int add_primitive_icosphere_exec(bContext *C, wmOperator *op)
unsigned int layer;
ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL);
make_prim_init(C, "Icosphere", &dia, mat, &state, loc, rot, layer);
obedit = CTX_data_edit_object(C);
obedit = make_prim_init(C, "Icosphere", &dia, mat, &state, loc, rot, layer);
em = BMEdit_FromObject(obedit);
if (!EDBM_op_call_and_selectf(
@ -545,7 +528,7 @@ static int add_primitive_icosphere_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
make_prim_finish(C, &state, enter_editmode);
make_prim_finish(C, obedit, &state, enter_editmode);
return OPERATOR_FINISHED;
}

@ -98,9 +98,8 @@ void load_editMball(Object *UNUSED(obedit))
}
/* Add metaelem primitive to metaball object (which is in edit mode) */
MetaElem *add_metaball_primitive(bContext *C, float mat[4][4], int type, int UNUSED(newname))
MetaElem *add_metaball_primitive(bContext *UNUSED(C), Object *obedit, float mat[4][4], int type, int UNUSED(newname))
{
Object *obedit = CTX_data_edit_object(C);
MetaBall *mball = (MetaBall *)obedit->data;
MetaElem *ml;

@ -439,7 +439,7 @@ static Object *effector_add_type(bContext *C, wmOperator *op, int type)
((Curve *)ob->data)->flag |= CU_PATH | CU_3D;
ED_object_enter_editmode(C, 0);
ED_object_new_primitive_matrix(C, ob, loc, rot, mat);
BLI_addtail(object_editcurve_get(ob), add_nurbs_primitive(C, mat, CU_NURBS | CU_PRIM_PATH, 1));
BLI_addtail(object_editcurve_get(ob), add_nurbs_primitive(C, ob, mat, CU_NURBS | CU_PRIM_PATH, 1));
if (!enter_editmode)
ED_object_exit_editmode(C, EM_FREEDATA);
@ -574,7 +574,7 @@ static int object_metaball_add_exec(bContext *C, wmOperator *op)
ED_object_new_primitive_matrix(C, obedit, loc, rot, mat);
/* elem= (MetaElem *) */ add_metaball_primitive(C, mat, RNA_enum_get(op->ptr, "type"), newob);
/* elem= (MetaElem *) */ add_metaball_primitive(C, obedit, mat, RNA_enum_get(op->ptr, "type"), newob);
/* userdef */
if (newob && !enter_editmode) {