Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2008-03-17 22:58:11 +0300
committerCampbell Barton <ideasman42@gmail.com>2008-03-17 22:58:11 +0300
commitbc7b18131b47c5a3638783e2138e2955e921f829 (patch)
tree8ec04accdff23940fa9c3254fc65e793cc712220 /source/blender/python
parent3de98a7cc1e8e2f9cd30d40c9e2273c1c94d62d4 (diff)
Running scripts with Blender.Run() would crash when reloading.
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/BPY_interface.c26
-rw-r--r--source/blender/python/api2_2x/Blender.c11
2 files changed, 28 insertions, 9 deletions
diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c
index d4a894e7661..a3c4f9d095e 100644
--- a/source/blender/python/BPY_interface.c
+++ b/source/blender/python/BPY_interface.c
@@ -785,14 +785,23 @@ int BPY_run_script(Script *script)
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 @@ int BPY_run_script(Script *script)
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 );
diff --git a/source/blender/python/api2_2x/Blender.c b/source/blender/python/api2_2x/Blender.c
index d520dded486..dbcd21f04f3 100644
--- a/source/blender/python/api2_2x/Blender.c
+++ b/source/blender/python/api2_2x/Blender.c
@@ -865,8 +865,15 @@ static PyObject *Blender_Run(PyObject *self, PyObject *value)
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;
}