Running scripts with Blender.Run() would crash when reloading.
This commit is contained in:
@@ -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 );
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user