Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2008-05-26 13:50:46 +0400
committerCampbell Barton <ideasman42@gmail.com>2008-05-26 13:50:46 +0400
commit0a90a52442071b8c346b8efade465eff714c37d8 (patch)
tree79e22fbb71f133d982fa40cac71d0556c4cd4196 /source/blender/src/editcurve.c
parentb7c6da39aedecb59b01ba8f833a8dc61afa89903 (diff)
* The displist would be uninitialized when nurbs bezieru/v was set and the order wasnt 3 or 4. add a function that checks nurbs can produce a valid line. check_valid_nurb_u/v
* when check_valid_nurb_u/v fails, no curve is allocated or drawn. * knotsu/v could be NULL but some functions didn't check for this, make sure this is checked for everywhere. * The interface didnt change check the order when the bezier u/v flag was set, added functions clamp_nurb_order_u/v that takes into accound the number of points and the bezier u/v flag.
Diffstat (limited to 'source/blender/src/editcurve.c')
-rw-r--r--source/blender/src/editcurve.c138
1 files changed, 76 insertions, 62 deletions
diff --git a/source/blender/src/editcurve.c b/source/blender/src/editcurve.c
index 7f9ba2cb8d2..3cb951c319b 100644
--- a/source/blender/src/editcurve.c
+++ b/source/blender/src/editcurve.c
@@ -335,7 +335,7 @@ void load_editNurb()
BLI_addtail(&(cu->nurb), newnu);
if((nu->type & 7)==CU_NURBS) {
- if(nu->pntsu < nu->orderu) nu->orderu= nu->pntsu;
+ clamp_nurb_order_u(nu);
}
}
}
@@ -689,7 +689,7 @@ void deleteflagNurb(short flag)
nu->pntsv= newv;
MEM_freeN(nu->bp);
nu->bp= newbp;
- if(nu->orderv>nu->pntsv) nu->orderv= nu->pntsv;
+ clamp_nurb_order_v(nu);
makeknots(nu, 2, nu->flagv>>1);
}
@@ -729,13 +729,13 @@ void deleteflagNurb(short flag)
nu->pntsu= nu->pntsv;
nu->pntsv= 1;
SWAP(short, nu->orderu, nu->orderv);
- if(nu->orderu>nu->pntsu) nu->orderu= nu->pntsu;
+ clamp_nurb_order_u(nu);
if(nu->knotsv) MEM_freeN(nu->knotsv);
- nu->knotsv= 0;
+ nu->knotsv= NULL;
}
else {
nu->pntsu= newu;
- if(nu->orderu>nu->pntsu) nu->orderu= nu->pntsu;
+ clamp_nurb_order_u(nu);
}
makeknots(nu, 1, nu->flagu>>1);
}
@@ -946,7 +946,7 @@ void adduplicateflagNurb(short flag)
}
/* knots */
- newnu->knotsu= 0;
+ newnu->knotsu= NULL;
makeknots(newnu, 1, newnu->flagu>>1);
}
bp++;
@@ -991,9 +991,11 @@ void adduplicateflagNurb(short flag)
newnu->pntsv= newv;
newnu->bp =
(BPoint*)MEM_mallocN(newu * newv * sizeof(BPoint), "adduplicateN6");
- newnu->orderu= MIN2(nu->orderu, newu);
- newnu->orderv= MIN2(nu->orderv, newv);
-
+ clamp_nurb_order_u(newnu);
+ clamp_nurb_order_v(newnu);
+
+ newnu->knotsu= newnu->knotsv= NULL;
+
bp= newnu->bp;
bp1= nu->bp;
for(a=0; a<nu->pntsv; a++) {
@@ -1005,23 +1007,20 @@ void adduplicateflagNurb(short flag)
}
}
}
- if(nu->pntsu==newnu->pntsu) {
- newnu->knotsu= MEM_mallocN(sizeof(float)*KNOTSU(nu), "adduplicateN6");
- memcpy(newnu->knotsu, nu->knotsu, sizeof(float)*KNOTSU(nu));
- }
- else {
- newnu->knotsu= 0;
- makeknots(newnu, 1, newnu->flagu>>1);
- }
- if(nu->pntsv==newnu->pntsv) {
- newnu->knotsv= MEM_mallocN(sizeof(float)*KNOTSV(nu), "adduplicateN7");
- memcpy(newnu->knotsv, nu->knotsv, sizeof(float)*KNOTSV(nu));
+ if (check_valid_nurb_u(newnu)) {
+ if(nu->pntsu==newnu->pntsu && nu->knotsu) {
+ newnu->knotsu= MEM_dupallocN( nu->knotsu );
+ } else {
+ makeknots(newnu, 1, newnu->flagu>>1);
+ }
}
- else {
- newnu->knotsv= 0;
- makeknots(newnu, 2, newnu->flagv>>1);
+ if (check_valid_nurb_v(newnu)) {
+ if(nu->pntsv==newnu->pntsv && nu->knotsv) {
+ newnu->knotsv= MEM_dupallocN( nu->knotsv );
+ } else {
+ makeknots(newnu, 2, newnu->flagv>>1);
+ }
}
-
}
MEM_freeN(usel);
}
@@ -2154,9 +2153,9 @@ int convertspline(short type, Nurb *nu)
if(type==0) { /* to Poly */
nu->type &= ~7;
if(nu->knotsu) MEM_freeN(nu->knotsu); /* python created nurbs have a knotsu of zero */
- nu->knotsu= 0;
+ nu->knotsu= NULL;
if(nu->knotsv) MEM_freeN(nu->knotsv);
- nu->knotsv= 0;
+ nu->knotsv= NULL;
}
else if(type==CU_BEZIER) { /* to Bezier */
nr= nu->pntsu/3;
@@ -2185,7 +2184,7 @@ int convertspline(short type, Nurb *nu)
MEM_freeN(nu->bp);
nu->bp= 0;
MEM_freeN(nu->knotsu);
- nu->knotsu= 0;
+ nu->knotsu= NULL;
nu->pntsu= nr;
nu->type &= ~7;
nu->type+= 1;
@@ -3042,26 +3041,28 @@ void makecyclicNurb()
calchandlesNurb(nu);
}
else if(nu->pntsv==1 && (nu->type & 7)==CU_NURBS) {
- a= nu->pntsu;
- bp= nu->bp;
- while(a--) {
- if( bp->f1 & SELECT ) {
- if(nu->flagu & CU_CYCLIC) nu->flagu--;
- else {
- nu->flagu++;
- nu->flagu &= ~2; /* endpoint flag, fixme */
- fp= MEM_mallocN(sizeof(float)*KNOTSU(nu), "makecyclicN");
- b= (nu->orderu+nu->pntsu);
- memcpy(fp, nu->knotsu, sizeof(float)*b);
- MEM_freeN(nu->knotsu);
- nu->knotsu= fp;
+ if (nu->knotsu) { /* if check_valid_nurb_u fails the knotsu can be NULL */
+ a= nu->pntsu;
+ bp= nu->bp;
+ while(a--) {
+ if( bp->f1 & SELECT ) {
+ if(nu->flagu & CU_CYCLIC) nu->flagu--;
+ else {
+ nu->flagu++;
+ nu->flagu &= ~2; /* endpoint flag, fixme */
+ fp= MEM_mallocN(sizeof(float)*KNOTSU(nu), "makecyclicN");
+ b= (nu->orderu+nu->pntsu);
+ memcpy(fp, nu->knotsu, sizeof(float)*b);
+ MEM_freeN(nu->knotsu);
+ nu->knotsu= fp;
- makeknots(nu, 1, 0); /* 1==u 0==uniform */
+ makeknots(nu, 1, 0); /* 1==u 0==uniform */
+ }
+ break;
}
- break;
+ bp++;
}
- bp++;
}
}
else if(nu->type==CU_NURBS) {
@@ -3078,26 +3079,34 @@ void makecyclicNurb()
if(nu->flagu & CU_CYCLIC) nu->flagu--;
else {
nu->flagu++;
- fp= MEM_mallocN(sizeof(float)*KNOTSU(nu), "makecyclicN");
- b= (nu->orderu+nu->pntsu);
- memcpy(fp, nu->knotsu, sizeof(float)*b);
- MEM_freeN(nu->knotsu);
- nu->knotsu= fp;
+ if (check_valid_nurb_u(nu)) {
+ fp= MEM_mallocN(sizeof(float)*KNOTSU(nu), "makecyclicN");
+ b= (nu->orderu+nu->pntsu);
+ if (nu->knotsu) { /* null if check_valid_nurb_u failed before but is valid now */
+ memcpy(fp, nu->knotsu, sizeof(float)*b);
+ MEM_freeN(nu->knotsu);
+ }
+ nu->knotsu= fp;
- makeknots(nu, 1, 0); /* 1==u 0==uniform */
+ makeknots(nu, 1, 0); /* 1==u 0==uniform */
+ }
}
}
if(cyclmode==2 && nu->pntsv>1) {
if(nu->flagv & 1) nu->flagv--;
else {
nu->flagv++;
- fp= MEM_mallocN(sizeof(float)*KNOTSV(nu), "makecyclicN");
- b= (nu->orderv+nu->pntsv);
- memcpy(fp, nu->knotsv, sizeof(float)*b);
- MEM_freeN(nu->knotsv);
- nu->knotsv= fp;
+ if (check_valid_nurb_v(nu)) {
+ fp= MEM_mallocN(sizeof(float)*KNOTSV(nu), "makecyclicN");
+ b= (nu->orderv+nu->pntsv);
+ if (nu->knotsv) { /* null if check_valid_nurb_v failed before but is valid now */
+ memcpy(fp, nu->knotsv, sizeof(float)*b);
+ MEM_freeN(nu->knotsv);
+ }
+ nu->knotsv= fp;
- makeknots(nu, 2, 0); /* 2==v 0==uniform */
+ makeknots(nu, 2, 0); /* 2==v 0==uniform */
+ }
}
}
break;
@@ -3674,10 +3683,13 @@ void delNurb()
}
}
- /* Never allow the order to exceed the number of points */
- if ((nu!= NULL) && ((nu->type & 7)==CU_NURBS) && (nu->pntsu < nu->orderu)) {
- nu->orderu = nu->pntsu;
+ /* Never allow the order to exceed the number of points
+ - note, this is ok but changes unselected nurbs, disable for now */
+ /*
+ if ((nu!= NULL) && ((nu->type & 7)==CU_NURBS)) {
+ clamp_nurb_order_u(nu);
}
+ */
nu= next;
}
/* 2nd loop, delete small pieces: just for curves */
@@ -3725,10 +3737,12 @@ void delNurb()
MEM_freeN(nu->bp);
nu->bp= bp1;
- /* Never allow the order to exceed the number of points */
- if ((nu->type & 7)==CU_NURBS && (nu->pntsu < nu->orderu)) {
- nu->orderu = nu->pntsu;
- }
+ /* Never allow the order to exceed the number of points\
+ - note, this is ok but changes unselected nurbs, disable for now */
+ /*
+ if ((nu->type & 7)==CU_NURBS) {
+ clamp_nurb_order_u(nu);
+ }*/
}
makeknots(nu, 1, nu->flagu>>1);
}