workaround for running python scripts before the contexts values are set.
authorCampbell Barton <ideasman42@gmail.com>
Wed, 27 Jan 2010 11:18:55 +0000 (11:18 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 27 Jan 2010 11:18:55 +0000 (11:18 +0000)
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

index 87662e0b7a515fc5248682b3cdda42d8afe4b816..9928ab0be6bb1fae3e7d0fff3c93de848891805c 100644 (file)
@@ -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) {