Commit: 2011156eec720a01088bc0bd02bd4021e39d7c65
Author: Campbell Barton
Date: Fri Jan 31 00:53:02 2014 +1100
https://developer.blender.org/rB2011156eec720a01088bc0bd02bd4021e39d7c65
Fix for crash linking node groups through bpy.data.library
Defer creating the Python objects until after appending is finished
because NodeTree's types are not initialized until then.
===================================================================
M source/blender/python/intern/bpy_library.c
===================================================================
diff --git a/source/blender/python/intern/bpy_library.c
b/source/blender/python/intern/bpy_library.c
index f4c21b1..7e84070 100644
--- a/source/blender/python/intern/bpy_library.c
+++ b/source/blender/python/intern/bpy_library.c
@@ -353,10 +353,9 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject
*UNUSED(args))
ID *id =
BLO_library_append_named_part(mainl, &(self->blo_handle), item_str, idcode);
if (id) {
#ifdef USE_RNA_DATABLOCKS
- PointerRNA
id_ptr;
-
RNA_id_pointer_create(id, &id_ptr);
+ /* swap name
for pointer to the id */
Py_DECREF(item);
- item =
pyrna_struct_CreatePyObject(&id_ptr);
+ item =
PyCapsule_New((void *)id, NULL, NULL);
#endif
}
else {
@@ -417,6 +416,38 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject
*UNUSED(args))
BKE_main_id_flag_all(bmain, LIB_PRE_EXISTING, false);
+ /* finally swap the capsules for real bpy objects
+ * important since BLO_library_append_end initializes NodeTree
types used by srna->refine */
+ {
+ int idcode_step = 0, idcode;
+ while ((idcode = BKE_idcode_iter_step(&idcode_step))) {
+ if (BKE_idcode_is_linkable(idcode)) {
+ const char *name_plural =
BKE_idcode_to_name_plural(idcode);
+ PyObject *ls =
PyDict_GetItemString(self->dict, name_plural);
+ if (ls && PyList_Check(ls)) {
+ Py_ssize_t size =
PyList_GET_SIZE(ls);
+ Py_ssize_t i;
+ PyObject *item;
+
+ for (i = 0; i < size; i++) {
+ item =
PyList_GET_ITEM(ls, i);
+ if
(PyCapsule_CheckExact(item)) {
+ PointerRNA
id_ptr;
+ ID *id;
+
+ id =
PyCapsule_GetPointer(item, NULL);
+ Py_DECREF(item);
+
+
RNA_id_pointer_create(id, &id_ptr);
+ item =
pyrna_struct_CreatePyObject(&id_ptr);
+
PyList_SET_ITEM(ls, i, item);
+ }
+ }
+ }
+ }
+ }
+ }
+
Py_RETURN_NONE;
}
}
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs