[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12498] trunk/blender/source/blender/ python: ==Python API==

Campbell Barton cbarton at metavr.com
Tue Nov 6 14:44:26 CET 2007


Revision: 12498
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12498
Author:   campbellbarton
Date:     2007-11-06 14:44:26 +0100 (Tue, 06 Nov 2007)

Log Message:
-----------
==Python API==
Bugfix, Space Handlers could crash blender when used with armatures.
also fixed some possible bugs in other areas.

Modified Paths:
--------------
    trunk/blender/source/blender/python/BPY_interface.c
    trunk/blender/source/blender/python/api2_2x/Armature.c

Modified: trunk/blender/source/blender/python/BPY_interface.c
===================================================================
--- trunk/blender/source/blender/python/BPY_interface.c	2007-11-06 12:16:12 UTC (rev 12497)
+++ trunk/blender/source/blender/python/BPY_interface.c	2007-11-06 13:44:26 UTC (rev 12498)
@@ -1938,6 +1938,7 @@
 	scriptlink = ID_getScriptlink( id );
 
 	if( scriptlink && scriptlink->totscript ) {
+		PyObject *value;
 		PyObject *dict;
 		PyObject *ret;
 		int index, during_slink = during_scriptlink(  );
@@ -1947,10 +1948,16 @@
 			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;
+		}
+		
 		/* tell we're running a scriptlink.  The sum also tells if this script
 		 * is running nested inside another.  Blender.Load needs this info to
 		 * avoid trouble with invalid slink pointers. */
@@ -1959,8 +1966,8 @@
 
 		/* 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 @@
 			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) */

Modified: trunk/blender/source/blender/python/api2_2x/Armature.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Armature.c	2007-11-06 12:16:12 UTC (rev 12497)
+++ trunk/blender/source/blender/python/api2_2x/Armature.c	2007-11-06 13:44:26 UTC (rev 12498)
@@ -1202,6 +1202,10 @@
 			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 @@
 				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;





More information about the Bf-blender-cvs mailing list