[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14158] trunk/blender/source/blender/ python: Running scripts with Blender.Run() would crash when reloading.

Campbell Barton ideasman42 at gmail.com
Mon Mar 17 20:58:12 CET 2008


Revision: 14158
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14158
Author:   campbellbarton
Date:     2008-03-17 20:58:11 +0100 (Mon, 17 Mar 2008)

Log Message:
-----------
Running scripts with Blender.Run() would crash when reloading.

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

Modified: trunk/blender/source/blender/python/BPY_interface.c
===================================================================
--- trunk/blender/source/blender/python/BPY_interface.c	2008-03-17 18:49:30 UTC (rev 14157)
+++ trunk/blender/source/blender/python/BPY_interface.c	2008-03-17 19:58:11 UTC (rev 14158)
@@ -785,14 +785,23 @@
 		char fname[FILE_MAX];
 		char fpath[FILE_MAX];
 		char ftmp[FILE_MAX];
+		char *bpyhome = bpy_gethome(1);
 		
-		strcpy(ftmp, script->scriptname);
-		BLI_split_dirfile(ftmp, fpath, fname);
-		BLI_make_file_string("/", fpath, bpy_gethome(1), fname);
+		if (bpyhome) {
+			BLI_strncpy(ftmp, script->scriptname, sizeof(ftmp));
+			BLI_split_dirfile(ftmp, fpath, fname); /* get the filename only - fname */
+			BLI_strncpy(fpath, bpy_gethome(1), sizeof(fpath));
+			BLI_add_slash(fpath);
+			strcat(fpath, fname);
 		
-		if (BLI_exists(fpath)) {
-			strncpy(script->scriptname, fpath, sizeof(script->scriptname));
-		} else if (U.pythondir[0]) {
+			if (BLI_exists(fpath)) {
+				strncpy(script->scriptname, fpath, sizeof(script->scriptname));
+			} else {
+				bpyhome = NULL; /* a bit dodgy, this is so the line below runs */
+			}
+		}
+		
+		if (bpyhome == NULL && U.pythondir[0]) {
 			BLI_make_file_string("/", fpath, U.pythondir, fname);
 			if (BLI_exists(fpath)) {
 				strncpy(script->scriptname, fpath, sizeof(script->scriptname));
@@ -812,7 +821,10 @@
 		Py_INCREF( Py_None );
 		pyarg = Py_None;
 	} else {
-		fp = fopen( script->scriptname, "rb" );
+		if (BLI_exists(script->scriptname)) {
+			fp = fopen( script->scriptname, "rb" );
+		}
+		
 		if( !fp ) {
 			printf( "Error loading script: couldn't open file %s\n", script->scriptname );
 			free_libblock( &G.main->script, script );

Modified: trunk/blender/source/blender/python/api2_2x/Blender.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Blender.c	2008-03-17 18:49:30 UTC (rev 14157)
+++ trunk/blender/source/blender/python/api2_2x/Blender.c	2008-03-17 19:58:11 UTC (rev 14158)
@@ -865,8 +865,15 @@
 
 	if (script) script->flags |= SCRIPT_RUNNING; /* set */
 
-	if (!is_blender_text) free_libblock(&G.main->text, text);
-
+	if (!is_blender_text) {
+		
+		/* nice to remember the original filename, so the script can run on reload */
+		if (script) {
+			strncpy(script->scriptname, fname, sizeof(script->scriptname));
+			script->scriptarg[0] = '\0';
+		}	
+		free_libblock(&G.main->text, text);
+	}
 	Py_RETURN_NONE;
 }
 





More information about the Bf-blender-cvs mailing list