==Python API==
authorCampbell Barton <ideasman42@gmail.com>
Tue, 6 Nov 2007 13:44:26 +0000 (13:44 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 6 Nov 2007 13:44:26 +0000 (13:44 +0000)
Bugfix, Space Handlers could crash blender when used with armatures.
also fixed some possible bugs in other areas.

source/blender/python/BPY_interface.c
source/blender/python/api2_2x/Armature.c

index 238c05d54a483dca73e67cbc0c3b73ea69a450bf..9c8203cf3fdeadaaab01182aa5b8c90be28c2aff 100644 (file)
@@ -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) */
index 47ee2564698e25028e302b7707a088cfcd89b258..6c22e831bd432d859fe5ec514c4d6c373b879596 100644 (file)
@@ -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;