[Bf-blender-cvs] [eaf815f] master: Fix for curve having invalid active vertex after setting type

Campbell Barton noreply at git.blender.org
Mon May 26 01:38:04 CEST 2014


Commit: eaf815f14a928f7d99db93013c9ad8daae539094
Author: Campbell Barton
Date:   Mon May 26 09:11:42 2014 +1000
https://developer.blender.org/rBeaf815f14a928f7d99db93013c9ad8daae539094

Fix for curve having invalid active vertex after setting type

also allow passing NULL vertex to BKE_curve_nurb_vert_active_set

===================================================================

M	source/blender/blenkernel/intern/curve.c
M	source/blender/editors/curve/editcurve.c
M	source/blender/makesrna/intern/rna_curve.c

===================================================================

diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index fa5e3dc..a61a15f 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -3830,6 +3830,9 @@ bool BKE_nurb_order_clamp_v(struct Nurb *nu)
 	return changed;
 }
 
+/**
+ * \note caller must ensure active vertex remains valid.
+ */
 bool BKE_nurb_type_convert(Nurb *nu, const short type, const bool use_handles)
 {
 	BezTriple *bezt;
@@ -4011,13 +4014,18 @@ void BKE_curve_nurb_vert_active_set(Curve *cu, Nurb *nu, void *vert)
 	if (nu) {
 		BKE_curve_nurb_active_set(cu, nu);
 
-		if (nu->type == CU_BEZIER) {
-			BLI_assert(ARRAY_HAS_ITEM((BezTriple *)vert, nu->bezt, nu->pntsu));
-			cu->actvert = (BezTriple *)vert - nu->bezt;
+		if (vert) {
+			if (nu->type == CU_BEZIER) {
+				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 {
-			BLI_assert(ARRAY_HAS_ITEM((BPoint *)vert, nu->bp, nu->pntsu * nu->pntsv));
-			cu->actvert = (BPoint *)vert - nu->bp;
+			cu->actvert = CU_ACT_NONE;
 		}
 	}
 	else {
diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c
index 2fdc9ff..f5cfc28 100644
--- a/source/blender/editors/curve/editcurve.c
+++ b/source/blender/editors/curve/editcurve.c
@@ -3916,6 +3916,7 @@ static int set_spline_type_exec(bContext *C, wmOperator *op)
 	ListBase *editnurb = object_editcurve_get(obedit);
 	Nurb *nu;
 	bool changed = false;
+	bool changed_size = false;
 	const bool use_handles = RNA_boolean_get(op->ptr, "use_handles");
 	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) {
 		if (isNurbsel(nu)) {
-			if (BKE_nurb_type_convert(nu, type, use_handles) == false)
-				BKE_report(op->reports, RPT_ERROR, "No conversion possible");
-			else
+			const int pntsu_prev = nu->pntsu;
+			if (BKE_nurb_type_convert(nu, type, use_handles)) {
 				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);
 		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;
 	}
 	else {
diff --git a/source/blender/makesrna/intern/rna_curve.c b/source/blender/makesrna/intern/rna_curve.c
index 79c19c4..29f1dd5 100644
--- a/source/blender/makesrna/intern/rna_curve.c
+++ b/source/blender/makesrna/intern/rna_curve.c
@@ -323,8 +323,15 @@ static int rna_Nurb_length(PointerRNA *ptr)
 
 static void rna_Nurb_type_set(PointerRNA *ptr, int value)
 {
+	Curve *cu = (Curve *)ptr->id.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)




More information about the Bf-blender-cvs mailing list