[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46437] trunk/blender/source/blender: Python/context: python could get invalid bpy. data in scene update handler after

Brecht Van Lommel brechtvanlommel at pandora.be
Wed May 9 00:07:07 CEST 2012


Revision: 46437
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46437
Author:   blendix
Date:     2012-05-08 22:07:06 +0000 (Tue, 08 May 2012)
Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/blender.c
    trunk/blender/source/blender/python/BPY_extern.h
    trunk/blender/source/blender/python/intern/bpy_interface.c
    trunk/blender/source/blender/python/intern/bpy_rna.c
    trunk/blender/source/blender/python/intern/bpy_util.h

Modified: trunk/blender/source/blender/blenkernel/intern/blender.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/blender.c	2012-05-08 20:18:33 UTC (rev 46436)
+++ trunk/blender/source/blender/blenkernel/intern/blender.c	2012-05-08 22:07:06 UTC (rev 46437)
@@ -91,6 +91,10 @@
 
 #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;
 UserDef U;
 /* ListBase = {NULL, NULL}; */
@@ -288,6 +292,11 @@
 
 	G.f = bfd->globalf;
 
+#ifdef WITH_PYTHON
+	/* let python know about new main */
+	BPY_context_update(C);
+#endif
+
 	if (!G.background) {
 		//setscreen(G.curscreen);
 	}

Modified: trunk/blender/source/blender/python/BPY_extern.h
===================================================================
--- trunk/blender/source/blender/python/BPY_extern.h	2012-05-08 20:18:33 UTC (rev 46436)
+++ trunk/blender/source/blender/python/BPY_extern.h	2012-05-08 22:07:06 UTC (rev 46437)
@@ -82,6 +82,7 @@
 void	BPY_DECREF(void *pyob_ptr);	/* Py_DECREF() */
 int		BPY_context_member_get(struct bContext *C, const char *member, struct bContextDataResult *result);
 void	BPY_context_set(struct bContext *C);
+void	BPY_context_update(struct bContext *C);
 
 void	BPY_id_release(struct ID *id);
 

Modified: trunk/blender/source/blender/python/intern/bpy_interface.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_interface.c	2012-05-08 20:18:33 UTC (rev 46436)
+++ trunk/blender/source/blender/python/intern/bpy_interface.c	2012-05-08 22:07:06 UTC (rev 46437)
@@ -96,7 +96,7 @@
 #endif
 
 /* 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
 	 * condition on C->data.recursion. ideal solution would be to disable
@@ -117,7 +117,7 @@
 		*gilstate = PyGILState_Ensure();
 
 	if (py_call_level == 1) {
-		bpy_context_update(C);
+		BPY_context_update(C);
 
 #ifdef TIME_PY_RUN
 		if (bpy_timer_count == 0) {
@@ -178,7 +178,8 @@
 
 	/* refreshes the main struct */
 	BPY_update_rna_module();
-	bpy_context_module->ptr.data = (void *)C;
+	if(bpy_context_module)
+		bpy_context_module->ptr.data = (void *)C;
 }
 
 void BPY_context_set(bContext *C)
@@ -623,7 +624,7 @@
 	/* update pointers since this can run from a nested script
 	 * on file load */
 	if (py_call_level) {
-		bpy_context_update(C);
+		BPY_context_update(C);
 	}
 
 	bpy_context_set(C, &gilstate);

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c	2012-05-08 20:18:33 UTC (rev 46436)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c	2012-05-08 22:07:06 UTC (rev 46437)
@@ -6339,11 +6339,13 @@
 
 void BPY_update_rna_module(void)
 {
+	if(rna_module_ptr) {
 #if 0
-	RNA_main_pointer_create(G.main, rna_module_ptr);
+		RNA_main_pointer_create(G.main, rna_module_ptr);
 #else
-	rna_module_ptr->data = G.main; /* just set data is enough */
+		rna_module_ptr->data = G.main; /* just set data is enough */
 #endif
+	}
 }
 
 #if 0

Modified: trunk/blender/source/blender/python/intern/bpy_util.h
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_util.h	2012-05-08 20:18:33 UTC (rev 46436)
+++ trunk/blender/source/blender/python/intern/bpy_util.h	2012-05-08 22:07:06 UTC (rev 46437)
@@ -49,7 +49,6 @@
 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