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:
authorWillian Padovani Germano <wpgermano@gmail.com>2005-05-25 08:52:52 +0400
committerWillian Padovani Germano <wpgermano@gmail.com>2005-05-25 08:52:52 +0400
commit2a1fe1b0cbbb45cbec7d9864ad79b1b321880da0 (patch)
tree098787ab375a550fd606ff7965a13d3e5b0960e7
parent524e411dbfce7702c270a590c78aba4012f66666 (diff)
BPython bug fixes:
- Patch #2491: Mathutils.AngleBetweenVecs BUGFIX http://projects.blender.org/tracker/?func=detail&aid=2491&group_id=9&atid=127 - #2607: Python String button can segfault if the allowable length is greater than 400 http://projects.blender.org/tracker/?func=detail&atid=125&aid=2607&group_id=9 - #2490: Vector == None gives warning http://projects.blender.org/tracker/?func=detail&aid=2490&group_id=9&atid=125 - #2476: Image.Draw() http://projects.blender.org/tracker/?func=detail&aid=2476&group_id=9&atid=125 All reported by Campbell, who also wrote the #2491 patch. Ken Hughes provided patches for #2490 and #2476. Thanks guys.
-rw-r--r--source/blender/python/api2_2x/Draw.c27
-rw-r--r--source/blender/python/api2_2x/Mathutils.c42
-rw-r--r--source/blender/python/api2_2x/vector.c7
3 files changed, 64 insertions, 12 deletions
diff --git a/source/blender/python/api2_2x/Draw.c b/source/blender/python/api2_2x/Draw.c
index 873e00b5a88..0c75ee22ab6 100644
--- a/source/blender/python/api2_2x/Draw.c
+++ b/source/blender/python/api2_2x/Draw.c
@@ -1045,6 +1045,11 @@ static PyObject *Method_String( PyObject * self, PyObject * args )
"expected a string, five ints, a string, an int and\n\
optionally another string as arguments" );
+ if (len > (UI_MAX_DRAW_STR - 1)) {
+ len = UI_MAX_DRAW_STR - 1;
+ newstr[len] = '\0';
+ }
+
real_len = strlen(newstr);
if (real_len > len) real_len = len;
@@ -1053,7 +1058,7 @@ static PyObject *Method_String( PyObject * self, PyObject * args )
but->slen = len;
but->val.asstr = MEM_mallocN( len + 1, "pybutton str" );
- BLI_strncpy( but->val.asstr, newstr, len + 1 ); /* adds '\0' */
+ BLI_strncpy( but->val.asstr, newstr, len + 1); /* adds '\0' */
but->val.asstr[real_len] = '\0';
if (info_arg[0] == '\0') info_str = info_str0;
@@ -1244,7 +1249,7 @@ static PyObject *Method_Image( PyObject * self, PyObject * args )
float originX, originY;
float zoomX = 1.0, zoomY = 1.0;
int clipX = 0, clipY = 0, clipW = -1, clipH = -1;
- GLfloat scissorBox[4];
+ /*GLfloat scissorBox[4];*/
/* parse the arguments passed-in from Python */
if( !PyArg_ParseTuple( args, "Off|ffiiii", &pyObjImage,
@@ -1301,10 +1306,28 @@ static PyObject *Method_Image( PyObject * self, PyObject * args )
* This particular technique is documented in the glRasterPos() man
* page, although I haven't seen it used elsewhere in Blender.
*/
+
+ /* update (W): to fix a bug where images wouldn't get drawn if the bottom
+ * left corner of the Scripts win were above a given height or to the right
+ * of a given width, the code below is being commented out. It should not
+ * be needed anyway, because spaces in Blender are projected to lie inside
+ * their areas, see src/drawscript.c for example. Note: the
+ * glaRasterPosSafe2i function in src/glutil.c does use the commented out
+ * technique, but with 0,0 instead of scissorBox. This function can be
+ * a little optimized, based on glaDrawPixelsSafe in that same fine, but
+ * we're too close to release 2.37 right now. */
+ /*
glGetFloatv( GL_SCISSOR_BOX, scissorBox );
glRasterPos2i( scissorBox[0], scissorBox[1] );
glBitmap( 0, 0, 0.0, 0.0,
originX-scissorBox[0], originY-scissorBox[1], NULL );
+ */
+
+ /* update (cont.): using these two lines instead:
+ * (based on glaRasterPosSafe2i, but Ken Hughes deserves credit
+ * for suggesting this exact fix in the bug tracker) */
+ glRasterPos2i(0, 0);
+ glBitmap( 0, 0, 0.0, 0.0, originX, originY, NULL );
/* set the zoom */
glPixelZoom( zoomX, zoomY );
diff --git a/source/blender/python/api2_2x/Mathutils.c b/source/blender/python/api2_2x/Mathutils.c
index 910b1587974..8c8a69f7a1d 100644
--- a/source/blender/python/api2_2x/Mathutils.c
+++ b/source/blender/python/api2_2x/Mathutils.c
@@ -25,7 +25,7 @@
*
* This is a new part of Blender.
*
- * Contributor(s): Joseph Gilbert
+ * Contributor(s): Joseph Gilbert, Campbell Barton
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
@@ -369,8 +369,19 @@ static PyObject *M_Mathutils_DotVecs( PyObject * self, PyObject * args )
static PyObject *M_Mathutils_AngleBetweenVecs( PyObject * self,
PyObject * args )
{
+ // original vectors, makea copy of these
VectorObject *vec1;
VectorObject *vec2;
+
+ /* copy of the 2 input vectors, these can be normalized
+ without input vectors being normalized. bugfix
+ no need to use vector objects, just use floats
+ No Chance of 4D vectors getting in.
+
+ Use doubles, since floats will return nan when input vecs are large.*/
+ double vec1copy[3];
+ double vec2copy[3];
+
float norm;
double dot, angleRads;
int x;
@@ -386,30 +397,43 @@ static PyObject *M_Mathutils_AngleBetweenVecs( PyObject * self,
if( vec1->size > 3 || vec2->size > 3 )
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
"only 2D,3D vectors are supported\n" ) );
-
- //normalize vec1
+
+ /* Check for 2 vectors being the same */
+ if (vec1->size == 3 &&
+ vec1->vec[0] == vec2->vec[0] &&
+ vec1->vec[1] == vec2->vec[1] &&
+ vec1->vec[2] == vec2->vec[2])
+ return PyFloat_FromDouble( dot ); /* 2 points are the same, return zero */
+ else if (vec1->size == 2 &&
+ vec1->vec[0] == vec2->vec[0] &&
+ vec1->vec[1] == vec2->vec[1])
+ return PyFloat_FromDouble( dot ); /* 2 points are the same, return zero */
+
+ //normalize vec1copy
norm = 0.0f;
for( x = 0; x < vec1->size; x++ ) {
- norm += vec1->vec[x] * vec1->vec[x];
+ vec1copy[x] = vec1->vec[x]; /* Assign new vector in the loop */
+ norm += vec1copy[x] * vec1copy[x];
}
norm = ( float ) sqrt( norm );
for( x = 0; x < vec1->size; x++ ) {
- vec1->vec[x] /= norm;
+ vec1copy[x] /= norm;
}
- //normalize vec2
+ //normalize vec2copy
norm = 0.0f;
for( x = 0; x < vec2->size; x++ ) {
- norm += vec2->vec[x] * vec2->vec[x];
+ vec2copy[x] = vec2->vec[x]; /* Assign new vector in the loop */
+ norm += vec2copy[x] * vec2copy[x];
}
norm = ( float ) sqrt( norm );
for( x = 0; x < vec2->size; x++ ) {
- vec2->vec[x] /= norm;
+ vec2copy[x] /= norm;
}
//dot product
for( x = 0; x < vec1->size; x++ ) {
- dot += vec1->vec[x] * vec2->vec[x];
+ dot += vec1copy[x] * vec2copy[x];
}
//I believe saacos checks to see if the vectors are normalized
diff --git a/source/blender/python/api2_2x/vector.c b/source/blender/python/api2_2x/vector.c
index 9e65de3c46d..049ed793de6 100644
--- a/source/blender/python/api2_2x/vector.c
+++ b/source/blender/python/api2_2x/vector.c
@@ -23,7 +23,7 @@
* All rights reserved.
*
*
- * Contributor(s): Willian P. Germano & Joseph Gilbert
+ * Contributor(s): Willian P. Germano, Joseph Gilbert, Ken Hughes
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
@@ -550,6 +550,10 @@ int Vector_coerce( PyObject ** v1, PyObject ** v2 )
printf( "vector/matrix numeric protocols unsupported...\n" );
Py_INCREF( *v1 );
return 0; //operation will type check
+ } else if( *v2 == Py_None ) {
+ Py_INCREF(*v1);
+ Py_INCREF(Py_None);
+ return 0;
} else if( PyNumber_Check( *v2 ) ) {
if( PyInt_Check( *v2 ) ) { //cast scalar to vector
tempI = PyMem_Malloc( 1 *
@@ -596,6 +600,7 @@ int Vector_coerce( PyObject ** v1, PyObject ** v2 )
//unknown type or numeric cast failure
printf( "attempting vector operation with unsupported type...\n" );
Py_INCREF( *v1 );
+ Py_INCREF( *v2 );
return 0; //operation will type check
}
} else {