[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11092] branches/pyapi_devel/source/ blender/python: fixed 2 areas where bad Vectors could be created.

Campbell Barton cbarton at metavr.com
Thu Jun 28 04:23:50 CEST 2007


Revision: 11092
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11092
Author:   campbellbarton
Date:     2007-06-28 04:23:06 +0200 (Thu, 28 Jun 2007)

Log Message:
-----------
fixed 2 areas where bad Vectors could be created.

 co = mesh.verts[0].co
 mesh.verts.delete(range(len(mesh.verts)))
 print co

Used to result in a vector with a bad pointer (memory corruption), but now the vector stores a pointer to the mesh vertex and updates its pointer whenever used.

 matrix = ob.matrixWorld.rotationPart()
 vec = matrix[0] # vector is linked to teh matrix
 matrix.resize4x4() # matrix data is reallocated
 
Now the vector points to the matrix and updates its pointer from the matricies whenever used.

If a vector with in invalid pointer is used it raises an error.

Modified Paths:
--------------
    branches/pyapi_devel/source/blender/python/BPY_interface.c
    branches/pyapi_devel/source/blender/python/api2_2x/Mathutils.c
    branches/pyapi_devel/source/blender/python/api2_2x/Mathutils.h
    branches/pyapi_devel/source/blender/python/api2_2x/Mesh.c
    branches/pyapi_devel/source/blender/python/api2_2x/Sound.c
    branches/pyapi_devel/source/blender/python/api2_2x/gen_utils.h
    branches/pyapi_devel/source/blender/python/api2_2x/matrix.c
    branches/pyapi_devel/source/blender/python/api2_2x/matrix.h
    branches/pyapi_devel/source/blender/python/api2_2x/vector.c
    branches/pyapi_devel/source/blender/python/api2_2x/vector.h

Modified: branches/pyapi_devel/source/blender/python/BPY_interface.c
===================================================================
--- branches/pyapi_devel/source/blender/python/BPY_interface.c	2007-06-27 15:08:31 UTC (rev 11091)
+++ branches/pyapi_devel/source/blender/python/BPY_interface.c	2007-06-28 02:23:06 UTC (rev 11092)
@@ -1368,7 +1368,7 @@
 	/* this is the reverse of code taken from newMatrix() */
 	for(row = 0; row < 4; row++) {
 		for(col = 0; col < 4; col++) {
-			obmat[row][col] = retmat->contigPtr[row*4+col];
+			obmat[row][col] = retmat->matrix[0][row*4+col];
 		}
 	}
 	
@@ -1521,7 +1521,7 @@
 	/* this is the reverse of code taken from newMatrix() */
 	for(row = 0; row < 4; row++) {
 		for(col = 0; col < 4; col++) {
-			targetmat[row][col] = retmat->contigPtr[row*4+col];
+			targetmat[row][col] = retmat->matrix[0][row*4+col];
 		}
 	}
 	

Modified: branches/pyapi_devel/source/blender/python/api2_2x/Mathutils.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Mathutils.c	2007-06-27 15:08:31 UTC (rev 11091)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Mathutils.c	2007-06-28 02:23:06 UTC (rev 11092)
@@ -47,26 +47,19 @@
 static char M_Mathutils_Euler_doc[] = "() - create and return a new euler object";
 static char M_Mathutils_Rand_doc[] = "() - return a random number";
 static char M_Mathutils_CrossVecs_doc[] = "() - returns a vector perpedicular to the 2 vectors crossed";
-static char M_Mathutils_CopyVec_doc[] = "() - create a copy of vector";
 static char M_Mathutils_DotVecs_doc[] = "() - return the dot product of two vectors";
 static char M_Mathutils_AngleBetweenVecs_doc[] = "() - returns the angle between two vectors in degrees";
 static char M_Mathutils_MidpointVecs_doc[] = "() - return the vector to the midpoint between two vectors";
-static char M_Mathutils_MatMultVec_doc[] = "() - multiplies a matrix by a column vector";
-static char M_Mathutils_VecMultMat_doc[] = "() - multiplies a row vector by a matrix";
 static char M_Mathutils_ProjectVecs_doc[] =	"() - returns the projection vector from the projection of vecA onto vecB";
 static char M_Mathutils_RotationMatrix_doc[] = "() - construct a rotation matrix from an angle and axis of rotation";
 static char M_Mathutils_ScaleMatrix_doc[] =	"() - construct a scaling matrix from a scaling factor";
 static char M_Mathutils_OrthoProjectionMatrix_doc[] = "() - construct a orthographic projection matrix from a selected plane";
 static char M_Mathutils_ShearMatrix_doc[] = "() - construct a shearing matrix from a plane of shear and a shear factor";
-static char M_Mathutils_CopyMat_doc[] = "() - create a copy of a matrix";
 static char M_Mathutils_TranslationMatrix_doc[] = "() - create a translation matrix from a vector";
-static char M_Mathutils_CopyQuat_doc[] = "() - copy quatB to quatA";
-static char M_Mathutils_CopyEuler_doc[] = "() - copy eulB to eultA";
 static char M_Mathutils_CrossQuats_doc[] = "() - return the mutliplication of two quaternions";
 static char M_Mathutils_DotQuats_doc[] = "() - return the dot product of two quaternions";
 static char M_Mathutils_Slerp_doc[] = "() - returns the interpolation between two quaternions";
 static char M_Mathutils_DifferenceQuats_doc[] = "() - return the angular displacment difference between two quats";
-static char M_Mathutils_RotateEuler_doc[] = "() - rotate euler by an axis and angle";
 static char M_Mathutils_Intersect_doc[] = "(v1, v2, v3, ray, orig, clip=1) - returns the intersection between a ray and a triangle, if possible, returns None otherwise";
 static char M_Mathutils_TriangleArea_doc[] = "(v1, v2, v3) - returns the area size of the 2D or 3D triangle defined";
 static char M_Mathutils_TriangleNormal_doc[] = "(v1, v2, v3) - returns the normal of the 3D triangle defined";
@@ -81,26 +74,19 @@
 	{"DotVecs", (PyCFunction) M_Mathutils_DotVecs, METH_VARARGS, M_Mathutils_DotVecs_doc},
 	{"AngleBetweenVecs", (PyCFunction) M_Mathutils_AngleBetweenVecs, METH_VARARGS, M_Mathutils_AngleBetweenVecs_doc},
 	{"MidpointVecs", (PyCFunction) M_Mathutils_MidpointVecs, METH_VARARGS, M_Mathutils_MidpointVecs_doc},
-	{"VecMultMat", (PyCFunction) M_Mathutils_VecMultMat, METH_VARARGS, M_Mathutils_VecMultMat_doc},
 	{"ProjectVecs", (PyCFunction) M_Mathutils_ProjectVecs, METH_VARARGS, M_Mathutils_ProjectVecs_doc},
-	{"CopyVec", (PyCFunction) M_Mathutils_CopyVec, METH_VARARGS, M_Mathutils_CopyVec_doc},
 	{"Matrix", (PyCFunction) M_Mathutils_Matrix, METH_VARARGS, M_Mathutils_Matrix_doc},
 	{"RotationMatrix", (PyCFunction) M_Mathutils_RotationMatrix, METH_VARARGS, M_Mathutils_RotationMatrix_doc},
 	{"ScaleMatrix", (PyCFunction) M_Mathutils_ScaleMatrix, METH_VARARGS, M_Mathutils_ScaleMatrix_doc},
 	{"ShearMatrix", (PyCFunction) M_Mathutils_ShearMatrix, METH_VARARGS, M_Mathutils_ShearMatrix_doc},
 	{"TranslationMatrix", (PyCFunction) M_Mathutils_TranslationMatrix, METH_VARARGS, M_Mathutils_TranslationMatrix_doc},
-	{"CopyMat", (PyCFunction) M_Mathutils_CopyMat, METH_VARARGS, M_Mathutils_CopyMat_doc},
 	{"OrthoProjectionMatrix", (PyCFunction) M_Mathutils_OrthoProjectionMatrix,  METH_VARARGS, M_Mathutils_OrthoProjectionMatrix_doc},
-	{"MatMultVec", (PyCFunction) M_Mathutils_MatMultVec, METH_VARARGS, M_Mathutils_MatMultVec_doc},
 	{"Quaternion", (PyCFunction) M_Mathutils_Quaternion, METH_VARARGS, M_Mathutils_Quaternion_doc},
-	{"CopyQuat", (PyCFunction) M_Mathutils_CopyQuat, METH_VARARGS, M_Mathutils_CopyQuat_doc},
 	{"CrossQuats", (PyCFunction) M_Mathutils_CrossQuats, METH_VARARGS, M_Mathutils_CrossQuats_doc},
 	{"DotQuats", (PyCFunction) M_Mathutils_DotQuats, METH_VARARGS, M_Mathutils_DotQuats_doc},
 	{"DifferenceQuats", (PyCFunction) M_Mathutils_DifferenceQuats, METH_VARARGS,M_Mathutils_DifferenceQuats_doc},
 	{"Slerp", (PyCFunction) M_Mathutils_Slerp, METH_VARARGS, M_Mathutils_Slerp_doc},
 	{"Euler", (PyCFunction) M_Mathutils_Euler, METH_VARARGS, M_Mathutils_Euler_doc},
-	{"CopyEuler", (PyCFunction) M_Mathutils_CopyEuler, METH_VARARGS, M_Mathutils_CopyEuler_doc},
-	{"RotateEuler", (PyCFunction) M_Mathutils_RotateEuler, METH_VARARGS, M_Mathutils_RotateEuler_doc},
 	{"Intersect", ( PyCFunction ) M_Mathutils_Intersect, METH_VARARGS, M_Mathutils_Intersect_doc},
 	{"TriangleArea", ( PyCFunction ) M_Mathutils_TriangleArea, METH_VARARGS, M_Mathutils_TriangleArea_doc},
 	{"TriangleNormal", ( PyCFunction ) M_Mathutils_TriangleNormal, METH_VARARGS, M_Mathutils_TriangleNormal_doc},
@@ -594,7 +580,7 @@
 			argSize = mat->rowSize; //rows
 			seqSize = mat->colSize; //col
 			for(i = 0; i < (seqSize * argSize); i++){
-				matrix[i] = mat->contigPtr[i];
+				matrix[i] = mat->matrix[0][i];
 			}
 		}
 		Py_DECREF(argObject);
@@ -1665,141 +1651,4 @@
 						"only 2D,3D vectors are supported\n" ) );
 	}
 }
-//#############################DEPRECATED################################
-//#######################################################################
-//----------------------------------Mathutils.CopyMat() -----------------
-//copies a matrix into a new matrix
-PyObject *M_Mathutils_CopyMat(PyObject * self, PyObject * args)
-{
-	PyObject *matrix = NULL;
-	static char warning = 1;
 
-	if( warning ) {
-		printf("Mathutils.CopyMat(): deprecated :use Mathutils.Matrix() to copy matrices\n");
-		--warning;
-	}
-
-	matrix = M_Mathutils_Matrix(self, args);
-	if(matrix == NULL)
-		return NULL; //error string already set if we get here
-	else
-		return matrix;
-}
-//----------------------------------Mathutils.CopyVec() -----------------
-//makes a new vector that is a copy of the input
-PyObject *M_Mathutils_CopyVec(PyObject * self, PyObject * args)
-{
-	PyObject *vec = NULL;
-	static char warning = 1;
-
-	if( warning ) {
-		printf("Mathutils.CopyVec(): Deprecated: use Mathutils.Vector() to copy vectors\n");
-		--warning;
-	}
-
-	vec = M_Mathutils_Vector(self, args);
-	if(vec == NULL)
-		return NULL; //error string already set if we get here
-	else
-		return vec;
-}
-//----------------------------------Mathutils.CopyQuat() --------------
-//Copies a quaternion to a new quat
-PyObject *M_Mathutils_CopyQuat(PyObject * self, PyObject * args)
-{
-	PyObject *quat = NULL;
-	static char warning = 1;
-
-	if( warning ) {
-		printf("Mathutils.CopyQuat(): Deprecated: use Mathutils.Quaternion() to copy vectors\n");
-		--warning;
-	}
-
-	quat = M_Mathutils_Quaternion(self, args);
-	if(quat == NULL)
-		return NULL; //error string already set if we get here
-	else
-		return quat;
-}
-//----------------------------------Mathutils.CopyEuler() ---------------
-//copies a euler to a new euler
-PyObject *M_Mathutils_CopyEuler(PyObject * self, PyObject * args)
-{
-	PyObject *eul = NULL;
-	static char warning = 1;
-
-	if( warning ) {
-		printf("Mathutils.CopyEuler(): deprecated:use Mathutils.Euler() to copy vectors\n");
-		--warning;
-	}
-
-	eul = M_Mathutils_Euler(self, args);
-	if(eul == NULL)
-		return NULL; //error string already set if we get here
-	else
-		return eul;
-}
-//----------------------------------Mathutils.RotateEuler() ------------
-//rotates a euler a certain amount and returns the result
-//should return a unique euler rotation (i.e. no 720 degree pitches :)
-PyObject *M_Mathutils_RotateEuler(PyObject * self, PyObject * args)
-{
-	EulerObject *Eul = NULL;
-	float angle;
-	char *axis;
-	static char warning = 1;
-
-	if( warning ) {
-		printf("Mathutils.RotateEuler(): Deprecated:use Euler.rotate() to rotate a euler\n");
-		--warning;
-	}
-
-	if(!PyArg_ParseTuple(args, "O!fs", &euler_Type, &Eul, &angle, &axis))
-		return EXPP_ReturnPyObjError(PyExc_TypeError,
-			   "Mathutils.RotateEuler(): expected euler type & float & string");
-
-	Euler_Rotate(Eul, Py_BuildValue("fs", angle, axis));
-	Py_RETURN_NONE;
-}
-//----------------------------------Mathutils.MatMultVec() --------------
-//COLUMN VECTOR Multiplication (Matrix X Vector)
-PyObject *M_Mathutils_MatMultVec(PyObject * self, PyObject * args)
-{
-	MatrixObject *mat = NULL;
-	VectorObject *vec = NULL;
-	static char warning = 1;
-
-	if( warning ) {
-		printf("Mathutils.MatMultVec(): Deprecated: use matrix * vec to perform column vector multiplication\n");
-		--warning;
-	}
-
-	//get pyObjects
-	if(!PyArg_ParseTuple(args, "O!O!", &matrix_Type, &mat, &vector_Type, &vec))
-		return EXPP_ReturnPyObjError(PyExc_TypeError, 
-			"Mathutils.MatMultVec(): MatMultVec() expects a matrix and a vector object - in that order\n");
-

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list