[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39567] trunk/blender/source/blender/ python/intern: fix for crash when loading a file from a script, and executing user modules in the newly loaded file.
Campbell Barton
ideasman42 at gmail.com
Sat Aug 20 15:29:42 CEST 2011
Revision: 39567
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39567
Author: campbellbarton
Date: 2011-08-20 13:29:42 +0000 (Sat, 20 Aug 2011)
Log Message:
-----------
fix for crash when loading a file from a script, and executing user modules in the newly loaded file.
Modified Paths:
--------------
trunk/blender/source/blender/python/intern/bpy_interface.c
trunk/blender/source/blender/python/intern/bpy_util.h
Modified: trunk/blender/source/blender/python/intern/bpy_interface.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_interface.c 2011-08-20 05:41:16 UTC (rev 39566)
+++ trunk/blender/source/blender/python/intern/bpy_interface.c 2011-08-20 13:29:42 UTC (rev 39567)
@@ -87,6 +87,14 @@
static double bpy_timer_run_tot; /* accumulate python runs */
#endif
+/* use for updating while a python script runs - in case of file load */
+void bpy_context_update(bContext *C)
+{
+ BPy_SetContext(C);
+ bpy_import_main_set(CTX_data_main(C));
+ BPY_modules_update(C); /* can give really bad results if this isnt here */
+}
+
void bpy_context_set(bContext *C, PyGILState_STATE *gilstate)
{
py_call_level++;
@@ -95,17 +103,8 @@
*gilstate= PyGILState_Ensure();
if(py_call_level==1) {
+ bpy_context_update(C);
- if(C) { // XXX - should always be true.
- BPy_SetContext(C);
- bpy_import_main_set(CTX_data_main(C));
- }
- else {
- fprintf(stderr, "ERROR: Python context called with a NULL Context. this should not happen!\n");
- }
-
- BPY_modules_update(C); /* can give really bad results if this isnt here */
-
#ifdef TIME_PY_RUN
if(bpy_timer_count==0) {
/* record time from the beginning */
@@ -570,6 +569,12 @@
if(bmain==NULL)
return;
+ /* update pointers since this can run from a nested script
+ * on file load */
+ if(py_call_level) {
+ bpy_context_update(C);
+ }
+
bpy_context_set(C, &gilstate);
for(text=CTX_data_main(C)->text.first; text; text= text->id.next) {
Modified: trunk/blender/source/blender/python/intern/bpy_util.h
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_util.h 2011-08-20 05:41:16 UTC (rev 39566)
+++ trunk/blender/source/blender/python/intern/bpy_util.h 2011-08-20 13:29:42 UTC (rev 39567)
@@ -51,6 +51,7 @@
struct bContext *BPy_GetContext(void);
void BPy_SetContext(struct bContext *C);
+extern void bpy_context_update(struct bContext *C);
extern void bpy_context_set(struct bContext *C, PyGILState_STATE *gilstate);
extern void bpy_context_clear(struct bContext *C, PyGILState_STATE *gilstate);
#endif
More information about the Bf-blender-cvs
mailing list