Python/context: python could get invalid bpy.data in scene update handler after
undo. The way this got updated from the context is a bit unreliable, and for handlers the update couldn't happen because there is no context passed in. Now it's updated from setup_app_data, which is where the change actually happens. I left in the other updates to be sure but they should not be needed anymore.
This commit is contained in:
@@ -91,6 +91,10 @@
|
|||||||
|
|
||||||
#include "WM_api.h" // XXXXX BAD, very BAD dependency (bad level call) - remove asap, elubie
|
#include "WM_api.h" // XXXXX BAD, very BAD dependency (bad level call) - remove asap, elubie
|
||||||
|
|
||||||
|
#ifdef WITH_PYTHON
|
||||||
|
#include "BPY_extern.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
Global G;
|
Global G;
|
||||||
UserDef U;
|
UserDef U;
|
||||||
/* ListBase = {NULL, NULL}; */
|
/* ListBase = {NULL, NULL}; */
|
||||||
@@ -288,6 +292,11 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath
|
|||||||
|
|
||||||
G.f = bfd->globalf;
|
G.f = bfd->globalf;
|
||||||
|
|
||||||
|
#ifdef WITH_PYTHON
|
||||||
|
/* let python know about new main */
|
||||||
|
BPY_context_update(C);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!G.background) {
|
if (!G.background) {
|
||||||
//setscreen(G.curscreen);
|
//setscreen(G.curscreen);
|
||||||
}
|
}
|
||||||
|
@@ -82,6 +82,7 @@ int BPY_string_exec(struct bContext *C, const char *expr);
|
|||||||
void BPY_DECREF(void *pyob_ptr); /* Py_DECREF() */
|
void BPY_DECREF(void *pyob_ptr); /* Py_DECREF() */
|
||||||
int BPY_context_member_get(struct bContext *C, const char *member, struct bContextDataResult *result);
|
int BPY_context_member_get(struct bContext *C, const char *member, struct bContextDataResult *result);
|
||||||
void BPY_context_set(struct bContext *C);
|
void BPY_context_set(struct bContext *C);
|
||||||
|
void BPY_context_update(struct bContext *C);
|
||||||
|
|
||||||
void BPY_id_release(struct ID *id);
|
void BPY_id_release(struct ID *id);
|
||||||
|
|
||||||
|
@@ -96,7 +96,7 @@ static double bpy_timer_run_tot; /* accumulate python runs */
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* use for updating while a python script runs - in case of file load */
|
/* use for updating while a python script runs - in case of file load */
|
||||||
void bpy_context_update(bContext *C)
|
void BPY_context_update(bContext *C)
|
||||||
{
|
{
|
||||||
/* don't do this from a non-main (e.g. render) thread, it can cause a race
|
/* don't do this from a non-main (e.g. render) thread, it can cause a race
|
||||||
* condition on C->data.recursion. ideal solution would be to disable
|
* condition on C->data.recursion. ideal solution would be to disable
|
||||||
@@ -117,7 +117,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);
|
BPY_context_update(C);
|
||||||
|
|
||||||
#ifdef TIME_PY_RUN
|
#ifdef TIME_PY_RUN
|
||||||
if (bpy_timer_count == 0) {
|
if (bpy_timer_count == 0) {
|
||||||
@@ -178,6 +178,7 @@ void BPY_modules_update(bContext *C)
|
|||||||
|
|
||||||
/* refreshes the main struct */
|
/* refreshes the main struct */
|
||||||
BPY_update_rna_module();
|
BPY_update_rna_module();
|
||||||
|
if(bpy_context_module)
|
||||||
bpy_context_module->ptr.data = (void *)C;
|
bpy_context_module->ptr.data = (void *)C;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -623,7 +624,7 @@ void BPY_modules_load_user(bContext *C)
|
|||||||
/* update pointers since this can run from a nested script
|
/* update pointers since this can run from a nested script
|
||||||
* on file load */
|
* on file load */
|
||||||
if (py_call_level) {
|
if (py_call_level) {
|
||||||
bpy_context_update(C);
|
BPY_context_update(C);
|
||||||
}
|
}
|
||||||
|
|
||||||
bpy_context_set(C, &gilstate);
|
bpy_context_set(C, &gilstate);
|
||||||
|
@@ -6339,12 +6339,14 @@ PyObject *BPY_rna_module(void)
|
|||||||
|
|
||||||
void BPY_update_rna_module(void)
|
void BPY_update_rna_module(void)
|
||||||
{
|
{
|
||||||
|
if(rna_module_ptr) {
|
||||||
#if 0
|
#if 0
|
||||||
RNA_main_pointer_create(G.main, rna_module_ptr);
|
RNA_main_pointer_create(G.main, rna_module_ptr);
|
||||||
#else
|
#else
|
||||||
rna_module_ptr->data = G.main; /* just set data is enough */
|
rna_module_ptr->data = G.main; /* just set data is enough */
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* This is a way we can access docstrings for RNA types
|
/* This is a way we can access docstrings for RNA types
|
||||||
|
@@ -49,7 +49,6 @@ 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