diff options
author | Campbell Barton <ideasman42@gmail.com> | 2007-11-06 16:44:26 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2007-11-06 16:44:26 +0300 |
commit | 6142ae3785dc62ccb187a345e02981494e7085bf (patch) | |
tree | b5fd765da833d66f9bdd26067e1fc1b85d311bc4 | |
parent | 9cd76a66096491e8994090e1992bb54d19c61950 (diff) |
==Python API==
Bugfix, Space Handlers could crash blender when used with armatures.
also fixed some possible bugs in other areas.
-rw-r--r-- | source/blender/python/BPY_interface.c | 18 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Armature.c | 9 |
2 files changed, 24 insertions, 3 deletions
diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c index 238c05d54a4..9c8203cf3fd 100644 --- a/source/blender/python/BPY_interface.c +++ b/source/blender/python/BPY_interface.c @@ -1938,6 +1938,7 @@ void BPY_do_pyscript( ID * id, short event ) scriptlink = ID_getScriptlink( id ); if( scriptlink && scriptlink->totscript ) { + PyObject *value; PyObject *dict; PyObject *ret; int index, during_slink = during_scriptlink( ); @@ -1947,7 +1948,13 @@ void BPY_do_pyscript( ID * id, short event ) return; if( !setup_armature_weakrefs()){ - printf("Oops - weakref dict\n"); + printf("Oops - weakref dict, this is a bug\n"); + return; + } + + value = GetPyObjectFromID( id ); + if( !value){ + printf("Oops - could not get a valid python object for Blender.link, this is a bug\n"); return; } @@ -1959,8 +1966,8 @@ void BPY_do_pyscript( ID * id, short event ) /* set globals in Blender module to identify scriptlink */ EXPP_dict_set_item_str( g_blenderdict, "bylink", EXPP_incr_ret_True() ); - EXPP_dict_set_item_str( g_blenderdict, "link", - GetPyObjectFromID( id ) ); + + EXPP_dict_set_item_str( g_blenderdict, "link", value ); EXPP_dict_set_item_str( g_blenderdict, "event", PyString_FromString( event_to_name ( event ) ) ); @@ -2178,6 +2185,11 @@ int BPY_do_spacehandlers( ScrArea *sa, unsigned short event, disable_where_scriptlink( (short)during_slink ); } + if( !setup_armature_weakrefs()){ + printf("Oops - weakref dict, this is a bug\n"); + return 0; + } + /* set globals in Blender module to identify space handler scriptlink */ EXPP_dict_set_item_str(g_blenderdict, "bylink", EXPP_incr_ret_True()); /* unlike normal scriptlinks, here Blender.link is int (space event type) */ diff --git a/source/blender/python/api2_2x/Armature.c b/source/blender/python/api2_2x/Armature.c index 47ee2564698..6c22e831bd4 100644 --- a/source/blender/python/api2_2x/Armature.c +++ b/source/blender/python/api2_2x/Armature.c @@ -1202,6 +1202,10 @@ static PyObject *M_Armature_Get(PyObject * self, PyObject * args) data = G.main->armature.first; //get the first data ID from the armature library while (data){ py_armature = Armature_CreatePyObject(data); //*new* + if (!py_armature) { + EXPP_decr2(seq, dict); + return NULL; /* error is set from Armature_CreatePyObject */ + } sprintf(buffer, "%s", ((bArmature*)data)->id.name +2); if(PyDict_SetItemString(dict, buffer, py_armature) == -1){ //add to dictionary EXPP_decr3(seq, dict, py_armature); @@ -1219,6 +1223,11 @@ static PyObject *M_Armature_Get(PyObject * self, PyObject * args) data = find_id("AR", name); //get data from library if (data != NULL){ py_armature = Armature_CreatePyObject(data); //*new* + if (!py_armature) { + EXPP_decr2(seq, dict); + return NULL; /* error is set from Armature_CreatePyObject */ + } + if(PyDict_SetItemString(dict, name, py_armature) == -1){ //add to dictionary EXPP_decr3(seq, dict, py_armature); goto RuntimeError; |