Fixed segmentation fault when non-curve object is setting as a taper
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 30 Mar 2010 14:33:05 +0000 (14:33 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 30 Mar 2010 14:33:05 +0000 (14:33 +0000)
Deny user to select non-curve objects for taper and bevel lists, also
added some checking into displist and curve modules - object could be
converted from curve to mesh (would be better to unset bevel/taper
object in this case -- will try to implement a bit later).

source/blender/blenkernel/intern/curve.c
source/blender/blenkernel/intern/displist.c
source/blender/makesrna/intern/rna_curve.c

index 9087a7ec4f2de126f294e96573f755cacfbec1eb..a95714e71d288b5a1ff5e465333969d9e5b01a2e 100644 (file)
@@ -1227,49 +1227,47 @@ void makebevelcurve(Scene *scene, Object *ob, ListBase *disp, int forRender)
        /* if a font object is being edited, then do nothing */
 // XXX if( ob == obedit && ob->type == OB_FONT ) return;
 
-       if(cu->bevobj && cu->bevobj!=ob) {
-               if(cu->bevobj->type==OB_CURVE) {
-                       bevcu= cu->bevobj->data;
-                       if(bevcu->ext1==0.0 && bevcu->ext2==0.0) {
-                               ListBase bevdisp= {NULL, NULL};
-                               facx= cu->bevobj->size[0];
-                               facy= cu->bevobj->size[1];
-
-                               if (forRender) {
-                                       makeDispListCurveTypes_forRender(scene, cu->bevobj, &bevdisp, NULL, 0);
-                                       dl= bevdisp.first;
-                               } else {
+       if(cu->bevobj && cu->bevobj!=ob && cu->bevobj->type==OB_CURVE) {
+               bevcu= cu->bevobj->data;
+               if(bevcu->ext1==0.0 && bevcu->ext2==0.0) {
+                       ListBase bevdisp= {NULL, NULL};
+                       facx= cu->bevobj->size[0];
+                       facy= cu->bevobj->size[1];
+
+                       if (forRender) {
+                               makeDispListCurveTypes_forRender(scene, cu->bevobj, &bevdisp, NULL, 0);
+                               dl= bevdisp.first;
+                       } else {
+                               dl= bevcu->disp.first;
+                               if(dl==0) {
+                                       makeDispListCurveTypes(scene, cu->bevobj, 0);
                                        dl= bevcu->disp.first;
-                                       if(dl==0) {
-                                               makeDispListCurveTypes(scene, cu->bevobj, 0);
-                                               dl= bevcu->disp.first;
-                                       }
                                }
+                       }
 
-                               while(dl) {
-                                       if ELEM(dl->type, DL_POLY, DL_SEGM) {
-                                               dlnew= MEM_mallocN(sizeof(DispList), "makebevelcurve1");                                        
-                                               *dlnew= *dl;
-                                               dlnew->verts= MEM_mallocN(3*sizeof(float)*dl->parts*dl->nr, "makebevelcurve1");
-                                               memcpy(dlnew->verts, dl->verts, 3*sizeof(float)*dl->parts*dl->nr);
-                                               
-                                               if(dlnew->type==DL_SEGM) dlnew->flag |= (DL_FRONT_CURVE|DL_BACK_CURVE);
-                                               
-                                               BLI_addtail(disp, dlnew);
-                                               fp= dlnew->verts;
-                                               nr= dlnew->parts*dlnew->nr;
-                                               while(nr--) {
-                                                       fp[2]= fp[1]*facy;
-                                                       fp[1]= -fp[0]*facx;
-                                                       fp[0]= 0.0;
-                                                       fp+= 3;
-                                               }
+                       while(dl) {
+                               if ELEM(dl->type, DL_POLY, DL_SEGM) {
+                                       dlnew= MEM_mallocN(sizeof(DispList), "makebevelcurve1");
+                                       *dlnew= *dl;
+                                       dlnew->verts= MEM_mallocN(3*sizeof(float)*dl->parts*dl->nr, "makebevelcurve1");
+                                       memcpy(dlnew->verts, dl->verts, 3*sizeof(float)*dl->parts*dl->nr);
+
+                                       if(dlnew->type==DL_SEGM) dlnew->flag |= (DL_FRONT_CURVE|DL_BACK_CURVE);
+
+                                       BLI_addtail(disp, dlnew);
+                                       fp= dlnew->verts;
+                                       nr= dlnew->parts*dlnew->nr;
+                                       while(nr--) {
+                                               fp[2]= fp[1]*facy;
+                                               fp[1]= -fp[0]*facx;
+                                               fp[0]= 0.0;
+                                               fp+= 3;
                                        }
-                                       dl= dl->next;
                                }
-
-                               freedisplist(&bevdisp);
+                               dl= dl->next;
                        }
+
+                       freedisplist(&bevdisp);
                }
        }
        else if(cu->ext1==0.0 && cu->ext2==0.0) {
index 29ee8aeab45ba72cec7b96e2a3fe2f066f5653d6..4defa0e53a17e8f3b3eabc0cc056716880aa1f01 100644 (file)
@@ -1755,8 +1755,10 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
                                                        bevp= (BevPoint *)(bl+1);
                                                        for(a=0; a<bl->nr; a++,bevp++) {
                                                                float fac=1.0;
-                                                               if (cu->taperobj==NULL) {
-                                                                       if ( (cu->bevobj!=NULL) || !((cu->flag & CU_FRONT) || (cu->flag & CU_BACK)) )
+                                                               if (cu->taperobj==NULL ||
+                                                                       cu->taperobj->type != OB_CURVE || cu->taperobj == ob) {
+                                                                       if ( (cu->bevobj!=NULL && cu->bevobj->type == OB_CURVE) ||
+                                                                               !((cu->flag & CU_FRONT) || (cu->flag & CU_BACK)) )
                                                                                fac = bevp->radius;
                                                                } else {
                                                                        fac = calc_taper(scene, cu->taperobj, a, bl->nr);
index 39ca635154388e1d75a6ee91e7af3e8147d4d283..dbea28c31f6dbd407a0adaac95016b09800b5741 100644 (file)
@@ -216,6 +216,30 @@ static void rna_Curve_update_deps(Main *bmain, Scene *scene, PointerRNA *ptr)
        rna_Curve_update_data(bmain, scene, ptr);
 }
 
+static void rna_Curve_update_taper(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+       Curve *cu= (Curve*)ptr->id.data;
+       Object *obj= cu->taperobj;
+
+       if (obj && obj->type != OB_CURVE) {
+               cu->taperobj = NULL;
+       }
+
+       rna_Curve_update_deps(bmain, scene, ptr);
+}
+
+static void rna_Curve_update_bevel(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+       Curve *cu= (Curve*)ptr->id.data;
+       Object *obj= cu->bevobj;
+
+       if (obj && obj->type != OB_CURVE) {
+               cu->bevobj = NULL;
+       }
+
+       rna_Curve_update_deps(bmain, scene, ptr);
+}
+
 static void rna_Curve_resolution_u_update_data(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
        Curve *cu= (Curve*)ptr->id.data;
@@ -1036,13 +1060,13 @@ static void rna_def_curve(BlenderRNA *brna)
        RNA_def_property_pointer_sdna(prop, NULL, "bevobj");
        RNA_def_property_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "Bevel Object", "Curve object name that defines the bevel shape");
-       RNA_def_property_update(prop, 0, "rna_Curve_update_deps");
+       RNA_def_property_update(prop, 0, "rna_Curve_update_bevel");
        
        prop= RNA_def_property(srna, "taper_object", PROP_POINTER, PROP_NONE);
        RNA_def_property_pointer_sdna(prop, NULL, "taperobj");
        RNA_def_property_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "Taper Object", "Curve object name that defines the taper (width)");
-       RNA_def_property_update(prop, 0, "rna_Curve_update_deps");
+       RNA_def_property_update(prop, 0, "rna_Curve_update_taper");
        
        /* Flags */