diff options
author | Campbell Barton <ideasman42@gmail.com> | 2008-08-04 05:57:22 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2008-08-04 05:57:22 +0400 |
commit | 3598dcd2796f819bd762f88c2d275816fed0e0d6 (patch) | |
tree | ef6697f5575c658e48a14f4efcffe43b94b8983d /source | |
parent | ae762bec91a75a3e66ac7876bb4f0eb23472f7e4 (diff) |
* 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
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/python/BPY_interface.c | 28 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Material.c | 12 | ||||
-rw-r--r-- | source/blender/src/header_info.c | 2 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.cpp | 50 |
4 files changed, 39 insertions, 53 deletions
diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c index 7120e97a62f..06e8c564ef0 100644 --- a/source/blender/python/BPY_interface.c +++ b/source/blender/python/BPY_interface.c @@ -160,7 +160,6 @@ ScriptError g_script_error; * 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 @@ int BPY_txt_do_python_Text( struct Text *text ) } /* 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 @@ int BPY_txt_do_python_Text( struct Text *text ) * 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 @@ PyObject *RunPython( Text * text, PyObject * globaldict ) 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 @@ PyObject *RunPython( Text * text, PyObject * globaldict ) } /***************************************************************************** -* 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 @@ PyObject *importText( char *name ) 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 @@ PyObject *importText( char *name ) 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 @@ static PyObject *reimportText( PyObject *module ) /* 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 @@ static PyObject *reimportText( PyObject *module ) /* 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 */ diff --git a/source/blender/python/api2_2x/Material.c b/source/blender/python/api2_2x/Material.c index c36213950b0..ccd24a437b5 100644 --- a/source/blender/python/api2_2x/Material.c +++ b/source/blender/python/api2_2x/Material.c @@ -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 @@ static PyMethodDef BPy_Material_methods[] = { "() - 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 @@ static PyMethodDef BPy_Material_methods[] = { "(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, diff --git a/source/blender/src/header_info.c b/source/blender/src/header_info.c index 4e43819cb71..a9280d9dd19 100644 --- a/source/blender/src/header_info.c +++ b/source/blender/src/header_info.c @@ -540,6 +540,7 @@ static void check_packAll() } } +#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 @@ static void copy_all_game_dlls(char *str) copy_game_dll(game_dll_list[i], source_dir, dest_dir ); }; } +#endif static int write_runtime(char *str, char *exename) { diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 6e922e421ac..6fcd3df2afc 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1368,14 +1368,15 @@ PyObject* KX_GameObject::PyGetMesh(PyObject* self, { 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 @@ KX_PYMETHODDEF_DOC(KX_GameObject, getVectTo, 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 @@ KX_PYMETHODDEF_DOC(KX_GameObject, getVectTo, 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 @@ KX_PYMETHODDEF_DOC(KX_GameObject, getVectTo, 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 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo, 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_PYMETHODDEF_DOC(KX_GameObject, rayCast, 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 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast, 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); |