From ba36ef9f3f7b6a8903acf5ddf4eba638048f2c6d Mon Sep 17 00:00:00 2001 From: Ken Hughes Date: Sat, 9 Dec 2006 06:17:14 +0000 Subject: [PATCH] Python API ---------- Bugfix #5373: creating a curve or text object using Object.New() without linking any data to the object would later cause a segfault when ob->data was later dereferenced. This problem will be fixed (hopefully soon) in the API when new objects are created with data and linked to scenes all in one step, but for now check for curves that ob->data is defined before using, otherwise print an error message to the console and skip the object. --- source/blender/blenkernel/intern/object.c | 8 ++++++ source/blender/python/api2_2x/Object.c | 33 ++++++++++++++++------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index a8bf87c966f..d92ec5d31b8 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -294,6 +294,14 @@ void unlink_object(Object *ob) if ELEM(obt->type, OB_CURVE, OB_FONT) { cu= obt->data; + /* this test is for a bug in the Python API with Object.New(): + * objects can be created without any obdata; when deleted, + * a segfault occurs since obt->data == NULL */ + if (!cu) { + printf ("ERROR: found curve object with no obdata!\n"); + break; + } + if(cu->bevobj==ob) { cu->bevobj= NULL; obt->recalc |= OB_RECALC; diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c index 10952629e6b..46998dae42d 100644 --- a/source/blender/python/api2_2x/Object.c +++ b/source/blender/python/api2_2x/Object.c @@ -770,6 +770,18 @@ static int Object_compare( BPy_Object * a, BPy_Object * b ); /* Function: M_Object_New */ /* Python equivalent: Blender.Object.New */ /*****************************************************************************/ + +/* + * Note: if this method is called without later linking object data to it, + * errors can be caused elsewhere in Blender. Future versions of the API + * will designate obdata as a parameter to this method to prevent this, and + * eventually this method will be deprecated. + * + * When we can guarantee that objects will always have valid obdata, + * unlink_object() should be edited to remove checks for NULL pointers and + * debugging messages. + */ + PyObject *M_Object_New( PyObject * self_unused, PyObject * args ) { struct Object *object; @@ -3104,18 +3116,21 @@ Object *GetObjectByName( char *name ) } /*****************************************************************************/ -/* Function: Object_dealloc */ -/* Description: This is a callback function for the BlenObject type. It is */ -/* the destructor function. */ +/* Function: Object_dealloc */ +/* Description: This is a callback function for the BlenObject type. It is */ +/* the destructor function. */ /*****************************************************************************/ -static void Object_dealloc( BPy_Object * obj ) +static void Object_dealloc( BPy_Object * self ) { -#if 1 /* this just adjust the ID but doesn't delete zero-user objects */ - obj->object->id.us--; -#else /* this will adjust the ID and if zero delete the object */ - free_libblock_us( &G.main->object, obj->object ); + if( self->object->data ) + self->object->id.us--; + else + free_libblock_us( &G.main->object, self->object ); + +#if 0 /* this will adjust the ID and if zero delete the object */ + free_libblock_us( &G.main->object, self->object ); #endif - PyObject_DEL( obj ); + PyObject_DEL( self ); } /*****************************************************************************/