From 3ab085a5b6bafe4e6a43c594f4c6dda9d9be17d7 Mon Sep 17 00:00:00 2001 From: Joseph Eagar Date: Tue, 30 Jan 2007 22:38:43 +0000 Subject: =Python bugfix= Armature code had missing NULL pointer check that crashed when used in pydrivers. --- source/blender/python/api2_2x/Armature.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 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 bb711ba49d9..658a06d4207 100644 --- a/source/blender/python/api2_2x/Armature.c +++ b/source/blender/python/api2_2x/Armature.c @@ -1351,12 +1351,12 @@ PyObject *PyArmature_FromArmature(struct bArmature *armature) PyObject *maindict = NULL, *armdict = NULL, *weakref = NULL; //create armature type - py_armature = (BPy_Armature*)Armature_Type.tp_alloc(&Armature_Type, 0); //*new* + 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) goto RuntimeError; py_armature->armature = armature; - + //create armature.bones py_armature->Bones = (BPy_BonesDict*)PyBonesDict_FromPyArmature(py_armature); if (!py_armature->Bones) @@ -1364,13 +1364,21 @@ PyObject *PyArmature_FromArmature(struct bArmature *armature) //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; } - return (PyObject *) py_armature; + return (PyObject *) py_armature; RuntimeError: return EXPP_objError(PyExc_RuntimeError, "%s%s%s", -- cgit v1.2.3