Fix for curve having invalid active vertex after setting type

also allow passing NULL vertex to BKE_curve_nurb_vert_active_set
This commit is contained in:
2014-05-26 09:11:42 +10:00
parent f574b1ca3c
commit eaf815f14a
3 changed files with 36 additions and 9 deletions

View File

@@ -3830,6 +3830,9 @@ bool BKE_nurb_order_clamp_v(struct Nurb *nu)
return changed; return changed;
} }
/**
* \note caller must ensure active vertex remains valid.
*/
bool BKE_nurb_type_convert(Nurb *nu, const short type, const bool use_handles) bool BKE_nurb_type_convert(Nurb *nu, const short type, const bool use_handles)
{ {
BezTriple *bezt; BezTriple *bezt;
@@ -4011,13 +4014,18 @@ void BKE_curve_nurb_vert_active_set(Curve *cu, Nurb *nu, void *vert)
if (nu) { if (nu) {
BKE_curve_nurb_active_set(cu, nu); BKE_curve_nurb_active_set(cu, nu);
if (nu->type == CU_BEZIER) { if (vert) {
BLI_assert(ARRAY_HAS_ITEM((BezTriple *)vert, nu->bezt, nu->pntsu)); if (nu->type == CU_BEZIER) {
cu->actvert = (BezTriple *)vert - nu->bezt; BLI_assert(ARRAY_HAS_ITEM((BezTriple *)vert, nu->bezt, nu->pntsu));
cu->actvert = (BezTriple *)vert - nu->bezt;
}
else {
BLI_assert(ARRAY_HAS_ITEM((BPoint *)vert, nu->bp, nu->pntsu * nu->pntsv));
cu->actvert = (BPoint *)vert - nu->bp;
}
} }
else { else {
BLI_assert(ARRAY_HAS_ITEM((BPoint *)vert, nu->bp, nu->pntsu * nu->pntsv)); cu->actvert = CU_ACT_NONE;
cu->actvert = (BPoint *)vert - nu->bp;
} }
} }
else { else {

View File

@@ -3916,6 +3916,7 @@ static int set_spline_type_exec(bContext *C, wmOperator *op)
ListBase *editnurb = object_editcurve_get(obedit); ListBase *editnurb = object_editcurve_get(obedit);
Nurb *nu; Nurb *nu;
bool changed = false; bool changed = false;
bool changed_size = false;
const bool use_handles = RNA_boolean_get(op->ptr, "use_handles"); const bool use_handles = RNA_boolean_get(op->ptr, "use_handles");
const int type = RNA_enum_get(op->ptr, "type"); const int type = RNA_enum_get(op->ptr, "type");
@@ -3926,10 +3927,16 @@ static int set_spline_type_exec(bContext *C, wmOperator *op)
for (nu = editnurb->first; nu; nu = nu->next) { for (nu = editnurb->first; nu; nu = nu->next) {
if (isNurbsel(nu)) { if (isNurbsel(nu)) {
if (BKE_nurb_type_convert(nu, type, use_handles) == false) const int pntsu_prev = nu->pntsu;
BKE_report(op->reports, RPT_ERROR, "No conversion possible"); if (BKE_nurb_type_convert(nu, type, use_handles)) {
else
changed = true; changed = true;
if (pntsu_prev != nu->pntsu) {
changed_size = true;
}
}
else {
BKE_report(op->reports, RPT_ERROR, "No conversion possible");
}
} }
} }
@@ -3940,6 +3947,11 @@ static int set_spline_type_exec(bContext *C, wmOperator *op)
DAG_id_tag_update(obedit->data, 0); DAG_id_tag_update(obedit->data, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
if (changed_size) {
Curve *cu = obedit->data;
cu->actvert = CU_ACT_NONE;
}
return OPERATOR_FINISHED; return OPERATOR_FINISHED;
} }
else { else {

View File

@@ -323,8 +323,15 @@ static int rna_Nurb_length(PointerRNA *ptr)
static void rna_Nurb_type_set(PointerRNA *ptr, int value) static void rna_Nurb_type_set(PointerRNA *ptr, int value)
{ {
Curve *cu = (Curve *)ptr->id.data;
Nurb *nu = (Nurb *)ptr->data; Nurb *nu = (Nurb *)ptr->data;
BKE_nurb_type_convert(nu, value, true); const int pntsu_prev = nu->pntsu;
if (BKE_nurb_type_convert(nu, value, true)) {
if (nu->pntsu != pntsu_prev) {
cu->actvert = CU_ACT_NONE;
}
}
} }
static void rna_BPoint_array_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) static void rna_BPoint_array_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)