From b22ebe667a7becef06e8212155e948c6bcc67d7d Mon Sep 17 00:00:00 2001 From: Ken Hughes Date: Thu, 20 Apr 2006 02:42:53 +0000 Subject: Bugfix #3889: action.setActive() was not adjusting id.us count correctly when a new action was set to active. --- source/blender/python/api2_2x/NLA.c | 52 ++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 21 deletions(-) (limited to 'source/blender/python/api2_2x/NLA.c') diff --git a/source/blender/python/api2_2x/NLA.c b/source/blender/python/api2_2x/NLA.c index dd891472155..ce69f42275f 100644 --- a/source/blender/python/api2_2x/NLA.c +++ b/source/blender/python/api2_2x/NLA.c @@ -281,22 +281,26 @@ static PyObject *Action_setActive( BPy_Action * self, PyObject * args ) BPy_Object *object; if( !self->action ) - ( EXPP_ReturnPyObjError( PyExc_RuntimeError, - "couldn't get attribute from a NULL action" ) ); + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute from a NULL action" ); if( !PyArg_ParseTuple( args, "O!", &Object_Type, &object ) ) - return ( EXPP_ReturnPyObjError( PyExc_AttributeError, - "expected python object argument" ) ); + return EXPP_ReturnPyObjError( PyExc_AttributeError, + "expected python object argument" ); - if( object->object->type != OB_ARMATURE ) { - return ( EXPP_ReturnPyObjError( PyExc_AttributeError, - "object not of type armature" ) ); - } - //set the active action to object + if( object->object->type != OB_ARMATURE ) + return EXPP_ReturnPyObjError( PyExc_AttributeError, + "object not of type armature" ); + + /* if object is already attached to an action, decrement user count */ + if( object->object->action ) + --object->object->action->id.us; + + /* set the active action to object */ object->object->action = self->action; + ++object->object->action->id.us; - Py_INCREF( Py_None ); - return Py_None; + Py_RETURN_NONE; } static PyObject *Action_getChannelIpo( BPy_Action * self, PyObject * args ) @@ -304,19 +308,19 @@ static PyObject *Action_getChannelIpo( BPy_Action * self, PyObject * args ) char *chanName; bActionChannel *chan; - if( !PyArg_ParseTuple( args, "s", &chanName ) ) { - EXPP_ReturnPyObjError( PyExc_AttributeError, + if( !PyArg_ParseTuple( args, "s", &chanName ) ) + return EXPP_ReturnPyObjError( PyExc_AttributeError, "string expected" ); - return NULL; - } chan = get_action_channel( self->action, chanName ); - if( chan == NULL ) { - EXPP_ReturnPyObjError( PyExc_AttributeError, - "no channel with that name..." ); - return NULL; + if( !chan ) + return EXPP_ReturnPyObjError( PyExc_ValueError, + "no channel with that name" ); + + if( !chan->ipo ) { + Py_RETURN_NONE; } - //return IPO + return Ipo_CreatePyObject( chan->ipo ); } @@ -375,7 +379,13 @@ static PyObject *Action_getAllChannelIpos( BPy_Action * self ) bActionChannel *chan = NULL; for( chan = self->action->chanbase.first; chan; chan = chan->next ) { - PyObject *ipo_attr = Ipo_CreatePyObject( chan->ipo ); + PyObject *ipo_attr; + if( chan->ipo ) + ipo_attr = Ipo_CreatePyObject( chan->ipo ); + else { + ipo_attr = Py_None; + Py_INCREF( ipo_attr ); + } if( ipo_attr ) { // Insert dict entry using the bone name as key if( PyDict_SetItemString( dict, chan->name, ipo_attr ) -- cgit v1.2.3