fix for crash when loading a file from a script, and executing user modules in the newly loaded file.
This commit is contained in:
@@ -87,6 +87,14 @@ static double bpy_timer_run; /* time for each python script run */
|
|||||||
static double bpy_timer_run_tot; /* accumulate python runs */
|
static double bpy_timer_run_tot; /* accumulate python runs */
|
||||||
#endif
|
#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)
|
void bpy_context_set(bContext *C, PyGILState_STATE *gilstate)
|
||||||
{
|
{
|
||||||
py_call_level++;
|
py_call_level++;
|
||||||
@@ -95,16 +103,7 @@ void bpy_context_set(bContext *C, PyGILState_STATE *gilstate)
|
|||||||
*gilstate= PyGILState_Ensure();
|
*gilstate= PyGILState_Ensure();
|
||||||
|
|
||||||
if(py_call_level==1) {
|
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
|
#ifdef TIME_PY_RUN
|
||||||
if(bpy_timer_count==0) {
|
if(bpy_timer_count==0) {
|
||||||
@@ -570,6 +569,12 @@ void BPY_modules_load_user(bContext *C)
|
|||||||
if(bmain==NULL)
|
if(bmain==NULL)
|
||||||
return;
|
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);
|
bpy_context_set(C, &gilstate);
|
||||||
|
|
||||||
for(text=CTX_data_main(C)->text.first; text; text= text->id.next) {
|
for(text=CTX_data_main(C)->text.first; text; text= text->id.next) {
|
||||||
|
@@ -51,6 +51,7 @@ short BPy_errors_to_report(struct ReportList *reports);
|
|||||||
struct bContext *BPy_GetContext(void);
|
struct bContext *BPy_GetContext(void);
|
||||||
void BPy_SetContext(struct bContext *C);
|
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_set(struct bContext *C, PyGILState_STATE *gilstate);
|
||||||
extern void bpy_context_clear(struct bContext *C, PyGILState_STATE *gilstate);
|
extern void bpy_context_clear(struct bContext *C, PyGILState_STATE *gilstate);
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user