From f5a48dfd31d8722f7a68199dd59d3a7e45f6d3ea Mon Sep 17 00:00:00 2001 From: Stephen Swaney Date: Wed, 31 Jan 2007 03:12:26 +0000 Subject: Bugfix for #5000 Setup for Armature weak ref list was missing from some places where we execute py code. This confused the interpreter and gave random attribute/tuple parse errors. Changed name of weak ref list to "__arm_weakrefs" to avoid name collision with user variables. --- source/blender/python/api2_2x/Armature.c | 38 +++++++++++++++++--------------- 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'source/blender/python/api2_2x/Armature.c') diff --git a/source/blender/python/api2_2x/Armature.c b/source/blender/python/api2_2x/Armature.c index 658a06d4207..d255183e71b 100644 --- a/source/blender/python/api2_2x/Armature.c +++ b/source/blender/python/api2_2x/Armature.c @@ -1348,36 +1348,38 @@ PyObject *Armature_RebuildBones(PyObject *pyarmature) PyObject *PyArmature_FromArmature(struct bArmature *armature) { BPy_Armature *py_armature = NULL; - PyObject *maindict = NULL, *armdict = NULL, *weakref = NULL; + PyObject *maindict = NULL, *weakref = NULL; + PyObject *armlist = NULL; /* list of armature weak refs */ + char *list_name = ARM_WEAKREF_LIST_NAME; //create armature type - py_armature = (BPy_Armature*)PyObject_New(BPy_Armature, &Armature_Type); //Armature_Type.tp_alloc(&Armature_Type, 0); //*new* - py_armature->weaklist = NULL; //init the weaklist - if (!py_armature) + py_armature = (BPy_Armature*)Armature_Type.tp_alloc(&Armature_Type, 0); /*new*/ + if (!py_armature){ + printf("Oops - can't create py armature\n"); goto RuntimeError; + } + + py_armature->weaklist = NULL; //init the weaklist py_armature->armature = armature; //create armature.bones py_armature->Bones = (BPy_BonesDict*)PyBonesDict_FromPyArmature(py_armature); - if (!py_armature->Bones) + if (!py_armature->Bones){ + printf("Oops - creating armature.bones\n"); goto RuntimeError; + } //put a weakreference in __main__ maindict= PyModule_GetDict(PyImport_AddModule( "__main__")); - - armdict = PyDict_GetItemString(maindict, "armatures"); - /*armature list doesn't exist for pydrivers. . .so check. - by the way, why is the var called armatures? what if a script author has - a similar var in his script? won't they conflict?. - - joeedh*/ - if (!armdict) return (PyObject *) py_armature; - - weakref = PyWeakref_NewProxy((PyObject*)py_armature, Py_None); - if (PyList_Append(armdict, weakref) == -1){ - goto RuntimeError; - } + armlist = PyDict_GetItemString(maindict, list_name); + if( armlist){ + weakref = PyWeakref_NewProxy((PyObject*)py_armature, Py_None); + if (PyList_Append(armlist, weakref) == -1){ + printf("Oops - list-append failed\n"); + goto RuntimeError; + } + } return (PyObject *) py_armature; RuntimeError: -- cgit v1.2.3