[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15942] trunk/blender/source: * KX_GameObject.cpp - error with getMesh(), was returning None rather then an error with invalid args.

Campbell Barton ideasman42 at gmail.com
Mon Aug 4 03:57:23 CEST 2008


Revision: 15942
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15942
Author:   campbellbarton
Date:     2008-08-04 03:57:22 +0200 (Mon, 04 Aug 2008)

Log Message:
-----------
* KX_GameObject.cpp - error with getMesh(), was returning None rather then an error with invalid args. also memory leak with getVectTo() if invalid args were given.
* Material.c - functions for get/setRayTransGlossSamples were not being used.
* BPY_interface.c - removed function GetName(), since everything else just uses id->name+2.
* header_info.c - added ifdef win32 around copy_game_dll since its not needed for other os's yet

Modified Paths:
--------------
    trunk/blender/source/blender/python/BPY_interface.c
    trunk/blender/source/blender/python/api2_2x/Material.c
    trunk/blender/source/blender/src/header_info.c
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp

Modified: trunk/blender/source/blender/python/BPY_interface.c
===================================================================
--- trunk/blender/source/blender/python/BPY_interface.c	2008-08-03 21:59:36 UTC (rev 15941)
+++ trunk/blender/source/blender/python/BPY_interface.c	2008-08-04 01:57:22 UTC (rev 15942)
@@ -160,7 +160,6 @@
 * Function prototypes 
 ***************************************************************************/
 PyObject *RunPython( Text * text, PyObject * globaldict );
-char *GetName( Text * text );
 PyObject *CreateGlobalDictionary( void );
 void ReleaseGlobalDictionary( PyObject * dict );
 void DoAllScriptsFromList( ListBase * list, short event );
@@ -651,7 +650,7 @@
 	}
 
 	/* Create a new script structure and initialize it: */
-	script = alloc_libblock( &G.main->script, ID_SCRIPT, GetName( text ) );
+	script = alloc_libblock( &G.main->script, ID_SCRIPT, text->id.name+2 );
 
 	if( !script ) {
 		printf( "couldn't allocate memory for Script struct!" );
@@ -662,8 +661,7 @@
 	 * an error after it will call BPY_Err_Handle below, but the text struct
 	 * will have been deallocated already, so we need to copy its name here.
 	 */
-	BLI_strncpy( textname, GetName( text ),
-		     strlen( GetName( text ) ) + 1 );
+	BLI_strncpy( textname, text->id.name+2, 21 );
 
 	script->id.us = 1;
 	script->flags = SCRIPT_RUNNING;
@@ -2724,8 +2722,7 @@
 		buf = txt_to_buf( text );
 
 		text->compiled =
-			Py_CompileString( buf, GetName( text ),
-					  Py_file_input );
+			Py_CompileString( buf, text->id.name+2, Py_file_input );
 
 		MEM_freeN( buf );
 
@@ -2740,15 +2737,6 @@
 }
 
 /*****************************************************************************
-* Description: This function returns the value of the name field of the	
-*	given Text struct.
-*****************************************************************************/
-char *GetName( Text * text )
-{
-	return ( text->id.name + 2 );
-}
-
-/*****************************************************************************
 * Description: This function creates a new Python dictionary object.
 *****************************************************************************/
 PyObject *CreateGlobalDictionary( void )
@@ -2809,7 +2797,7 @@
 	text = ( Text * ) & ( G.main->text.first );
 
 	while( text ) {
-		if( !strcmp( txtname, GetName( text ) ) )
+		if( !strcmp( txtname, text->id.name+2 ) )
 			break;
 		text = text->id.next;
 	}
@@ -2822,8 +2810,7 @@
 	if( !text->compiled ) {
 		buf = txt_to_buf( text );
 		text->compiled =
-			Py_CompileString( buf, GetName( text ),
-					  Py_file_input );
+			Py_CompileString( buf, text->id.name+2, Py_file_input );
 		MEM_freeN( buf );
 
 		if( PyErr_Occurred(  ) ) {
@@ -2905,7 +2892,7 @@
 	/* look up the text object */
 	text = ( Text * ) & ( G.main->text.first );
 	while( text ) {
-		if( !strcmp( txtname, GetName( text ) ) )
+		if( !strcmp( txtname, text->id.name+2 ) )
 			break;
 		text = text->id.next;
 	}
@@ -2922,8 +2909,7 @@
 
 	/* compile the buffer */
 	buf = txt_to_buf( text );
-	text->compiled = Py_CompileString( buf, GetName( text ),
-			Py_file_input );
+	text->compiled = Py_CompileString( buf, text->id.name+2, Py_file_input );
 	MEM_freeN( buf );
 
 	/* if compile failed.... return this error */

Modified: trunk/blender/source/blender/python/api2_2x/Material.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Material.c	2008-08-03 21:59:36 UTC (rev 15941)
+++ trunk/blender/source/blender/python/api2_2x/Material.c	2008-08-04 01:57:22 UTC (rev 15942)
@@ -131,11 +131,11 @@
 #define EXPP_MAT_RAYMIRRGLOSS_MIN			 0.0
 #define EXPP_MAT_RAYMIRRGLOSS_MAX			 1.0
 #define EXPP_MAT_RAYMIRRGLOSSSAMPLES_MIN	 0
-#define EXPP_MAT_RAYMIRRGLOSSSAMPLES_MAX	 255
+#define EXPP_MAT_RAYMIRRGLOSSSAMPLES_MAX	 1024
 #define EXPP_MAT_RAYTRANSPGLOSS_MIN			 0.0
 #define EXPP_MAT_RAYTRANSPGLOSS_MAX			 1.0
 #define EXPP_MAT_RAYTRANSPGLOSSSAMPLES_MIN	 0
-#define EXPP_MAT_RAYTRANSPGLOSSSAMPLES_MAX	 255
+#define EXPP_MAT_RAYTRANSPGLOSSSAMPLES_MAX	 1024
 #define EXPP_MAT_FILTER_MIN			0.0
 #define EXPP_MAT_FILTER_MAX			1.0
 #define EXPP_MAT_TRANSLUCENCY_MIN			0.0
@@ -738,8 +738,10 @@
 	 "() - Return fresnel power for refractions factor"},
 	{"getRayTransGloss", ( PyCFunction ) Material_getGlossTrans, METH_NOARGS,
 	 "() - Return amount refraction glossiness"},
+	{"getRayTransGlossSamples", ( PyCFunction ) Material_getGlossTransSamples, METH_NOARGS,
+	 "() - Return number of sampels for transparent glossiness"},
 	{"getRayMirrGlossSamples", ( PyCFunction ) Material_getGlossMirrSamples, METH_NOARGS,
-	 "() - Return amount mirror glossiness"},
+	 "() - Return number of sampels for mirror glossiness"},
 	{"getFilter", ( PyCFunction ) Material_getFilter, METH_NOARGS,
 	 "() - Return the amount of filtering when transparent raytrace is enabled"},
 	{"getTranslucency", ( PyCFunction ) Material_getTranslucency, METH_NOARGS,
@@ -847,8 +849,10 @@
 	 "(f) - Set blend fac for mirror fresnel - [1.0, 5.0]"},
 	{"setRayTransGloss", ( PyCFunction ) Material_setGlossTrans, METH_VARARGS,
 	 "(f) - Set amount refraction glossiness - [0.0, 1.0]"},
+	{"setRayTransGlossSamples", ( PyCFunction ) Material_setGlossTransSamples, METH_VARARGS,
+	 "(i) - Set number transparent gloss samples - [1, 1024]"},
 	{"setRayMirrGlossSamples", ( PyCFunction ) Material_setGlossMirrSamples, METH_VARARGS,
-	 "(f) - Set amount mirror glossiness - [0.0, 1.0]"},
+	 "(i) - Set number mirror gloss samples - [1, 1024]"},
 	{"setFilter", ( PyCFunction ) Matr_oldsetFilter, METH_VARARGS,
 	 "(f) - Set the amount of filtering when transparent raytrace is enabled"},
 	{"setTranslucency", ( PyCFunction ) Matr_oldsetTranslucency, METH_VARARGS,

Modified: trunk/blender/source/blender/src/header_info.c
===================================================================
--- trunk/blender/source/blender/src/header_info.c	2008-08-03 21:59:36 UTC (rev 15941)
+++ trunk/blender/source/blender/src/header_info.c	2008-08-04 01:57:22 UTC (rev 15942)
@@ -540,6 +540,7 @@
 	}
 }
 
+#ifdef _WIN32
 static void copy_game_dll(char *dll_filename, char *source_dir, char *dest_dir)
 {
 	char source_filename[FILE_MAX];
@@ -573,6 +574,7 @@
 		copy_game_dll(game_dll_list[i], source_dir, dest_dir );
 	};
 }
+#endif
 
 static int write_runtime(char *str, char *exename)
 {

Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp	2008-08-03 21:59:36 UTC (rev 15941)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp	2008-08-04 01:57:22 UTC (rev 15942)
@@ -1368,14 +1368,15 @@
 {
 	int mesh = 0;
 
-	if (PyArg_ParseTuple(args, "|i", &mesh))
+	if (!PyArg_ParseTuple(args, "|i", &mesh))
+		return NULL; // python sets a simple error
+	
+	if (((unsigned int)mesh < m_meshes.size()) && mesh >= 0)
 	{
-		if (((unsigned int)mesh < m_meshes.size()) && mesh >= 0)
-		{
-			KX_MeshProxy* meshproxy = new KX_MeshProxy(m_meshes[mesh]);
-			return meshproxy;
-		}
+		KX_MeshProxy* meshproxy = new KX_MeshProxy(m_meshes[mesh]);
+		return meshproxy;
 	}
+	
 	Py_RETURN_NONE;
 }
 
@@ -1564,14 +1565,9 @@
 	MT_Vector3 toDir, locToDir;
 	MT_Scalar distance;
 
-	PyObject *returnValue = PyTuple_New(3);
+	PyObject *returnValue;
 	PyObject *pyother;
 
-	if (!returnValue)
-	{
-		PyErr_SetString(PyExc_MemoryError, "PyTuple_New() failed");
-		return NULL;
-	}
 	if (!PyVecArgTo(args, toPoint))
 	{
 		PyErr_Clear();
@@ -1581,7 +1577,7 @@
 			toPoint = other->NodeGetWorldPosition();
 		}else
 		{
-			PyErr_SetString(PyExc_TypeError, "Invalid arguments");
+			PyErr_SetString(PyExc_TypeError, "Expected a 3D Vector or GameObject type");
 			return NULL;
 		}
 	}
@@ -1599,11 +1595,13 @@
 		toDir.normalize();
 		locToDir = toDir * NodeGetWorldOrientation();
 	}
-
-	PyTuple_SET_ITEM(returnValue, 0, PyFloat_FromDouble(distance));
-	PyTuple_SET_ITEM(returnValue, 1, PyObjectFrom(toDir));
-	PyTuple_SET_ITEM(returnValue, 2, PyObjectFrom(locToDir));
-
+	
+	returnValue = PyTuple_New(3);
+	if (returnValue) { // very unlikely to fail, python sets a memory error here.
+		PyTuple_SET_ITEM(returnValue, 0, PyFloat_FromDouble(distance));
+		PyTuple_SET_ITEM(returnValue, 1, PyObjectFrom(toDir));
+		PyTuple_SET_ITEM(returnValue, 2, PyObjectFrom(locToDir));
+	}
 	return returnValue;
 }
 
@@ -1640,8 +1638,7 @@
 	char *propName = NULL;
 
 	if (!PyArg_ParseTuple(args,"O|fs", &pyarg, &dist, &propName)) {
-		PyErr_SetString(PyExc_TypeError, "Invalid arguments");
-		return NULL;
+		return NULL; // python sets simple error
 	}
 
 	if (!PyVecTo(pyarg, toPoint))
@@ -1706,8 +1703,7 @@
 	KX_GameObject *other;
 
 	if (!PyArg_ParseTuple(args,"O|Ofs", &pyto, &pyfrom, &dist, &propName)) {
-		PyErr_SetString(PyExc_TypeError, "Invalid arguments");
-		return NULL;
+		return NULL; // Python sets a simple error
 	}
 
 	if (!PyVecTo(pyto, toPoint))
@@ -1766,13 +1762,11 @@
     if (m_pHitObject)
 	{
 		PyObject* returnValue = PyTuple_New(3);
-		if (!returnValue) {
-			PyErr_SetString(PyExc_TypeError, "PyTuple_New() failed");
-			return NULL;
+		if (returnValue) { // unlikely this would ever fail, if it does python sets an error
+			PyTuple_SET_ITEM(returnValue, 0, m_pHitObject->AddRef());
+			PyTuple_SET_ITEM(returnValue, 1, PyObjectFrom(resultPoint));
+			PyTuple_SET_ITEM(returnValue, 2, PyObjectFrom(resultNormal));
 		}
-		PyTuple_SET_ITEM(returnValue, 0, m_pHitObject->AddRef());
-		PyTuple_SET_ITEM(returnValue, 1, PyObjectFrom(resultPoint));
-		PyTuple_SET_ITEM(returnValue, 2, PyObjectFrom(resultNormal));
 		return returnValue;
 	}
 	return Py_BuildValue("OOO", Py_None, Py_None, Py_None);





More information about the Bf-blender-cvs mailing list