From 7a959059029bcd5abf0a41655d6eb07eb6ef725c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 27 Jan 2010 11:18:55 +0000 Subject: [PATCH] workaround for running python scripts before the contexts values are set. not happy with this but running python scripts with the -P command line could crash in simple cases (like selecting an object). --- source/creator/creator.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/source/creator/creator.c b/source/creator/creator.c index 87662e0b7a5..9928ab0be6b 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -707,10 +707,26 @@ int main(int argc, char **argv) case 'P': #ifndef DISABLE_PYTHON - //XXX - // FOR TESTING ONLY a++; - BPY_run_python_script(C, argv[a], NULL, NULL); // use reports? + + /* workaround for scripts not getting a bpy.context.scene, causes internal errors elsewhere */ + { + /* XXX, temp setting the WM is ugly, splash also does this :S */ + wmWindowManager *wm= CTX_wm_manager(C); + wmWindow *prevwin= CTX_wm_window(C); + + if(wm->windows.first) { + CTX_wm_window_set(C, wm->windows.first); + + BPY_run_python_script(C, argv[a], NULL, NULL); // use reports? + + CTX_wm_window_set(C, prevwin); + } + else { + fprintf(stderr, "Python script \"%s\" running with missing context data.\n", argv[a]); + BPY_run_python_script(C, argv[a], NULL, NULL); // use reports? + } + } #if 0 a++; if (a < argc) {