When converting from TF_SELECT to use the mfaces selection flag only I missed getSele...
authorCampbell Barton <ideasman42@gmail.com>
Fri, 1 Jun 2007 02:33:23 +0000 (02:33 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 1 Jun 2007 02:33:23 +0000 (02:33 +0000)
This broke theeths UV-Exportscript.
updated and added 2 missing decref's, as well as a check not to write a list of faces greater then the size of the NMesh (mesh and NMesh face lengths can differ)

source/blender/python/api2_2x/NMesh.c

index 5c86a3448967de374ba5c7e007e919339f8eb696..b0ab64a6249ea77d4682524248874e7fd3c17cb0 100644 (file)
@@ -1278,23 +1278,33 @@ static PyObject *NMesh_getSelectedFaces( PyObject * self, PyObject * args )
        Mesh *me = nm->mesh;
        int flag = 0;
        
-       MTFace *tf;
+       MFace *mf;
        int i;
        PyObject *l = PyList_New( 0 ), *pyval;
 
-       if( me == NULL )
+       /* dont allow returning more then the NMesh's number of faces */
+       int totfaces = PySequence_Length(nm->faces);
+       
+       if( me == NULL ) {
+               Py_DECREF(l);
                return NULL;
-
-       tf = me->mtface;
-       if( tf == 0 )
+       }
+       mf = me->mface;
+       if( mf == NULL )
                return l;
 
-       if( !PyArg_ParseTuple( args, "|i", &flag ) )
+       if( !PyArg_ParseTuple( args, "|i", &flag ) ) {
+               Py_DECREF(l);
                return NULL;
-
+       }
+       
+       /* make sure not to write more faces then we have */
+       if (totfaces > me->totface)
+               totfaces= me->totface;
+       
        if( flag ) {
                for( i = 0; i < me->totface; i++ ) {
-                       if( tf[i].flag & TF_SELECT ) {
+                       if( mf[i].flag & ME_FACE_SEL ) {
                                pyval = PyInt_FromLong( i );
                                PyList_Append( l, pyval );
                                Py_DECREF(pyval);
@@ -1302,7 +1312,7 @@ static PyObject *NMesh_getSelectedFaces( PyObject * self, PyObject * args )
                }
        } else {
                for( i = 0; i < me->totface; i++ ) {
-                       if( tf[i].flag & TF_SELECT )
+                       if( mf[i].flag & ME_FACE_SEL )
                                PyList_Append( l, PyList_GetItem( nm->faces, i ) );
                }
        }