From cd934aa1a80e29aebb173d993497685fd29657bf Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Sun, 24 Feb 2008 06:38:42 +0000 Subject: Patch #8344: Submitted by: Thomas Knight (epat) Parts committed: 1) Fixed a few misspellings in some error strings. 2) Fixed a (theoretical) bug with pyconstraints where a text object could be deleted from python but would remain linked to the constraint it was assigned to - causing slight UI usage discontinuities! Not committed yet: 3) Particle system bugfix in this patch has not been committed. Could jahka or brecht check this. --- source/blender/python/BPY_extern.h | 1 + source/blender/python/BPY_interface.c | 39 ++++++++++++++++++++++++++++++++ source/blender/python/api2_2x/Text.c | 3 ++- source/blender/python/api2_2x/bpy_data.c | 5 ++-- source/blender/src/header_text.c | 34 +--------------------------- 5 files changed, 46 insertions(+), 36 deletions(-) (limited to 'source') diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h index 8b4760fe25d..c3aef82751d 100644 --- a/source/blender/python/BPY_extern.h +++ b/source/blender/python/BPY_extern.h @@ -79,6 +79,7 @@ extern "C" { void BPY_pyconstraint_target(struct bPythonConstraint *con, struct bConstraintTarget *ct); void BPY_pyconstraint_update(struct Object *owner, struct bConstraint *con); int BPY_is_pyconstraint(struct Text *text); + void BPY_free_pyconstraint_links(struct Text *text); void BPY_start_python( int argc, char **argv ); void BPY_end_python( void ); diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c index b1fd48d87e6..04d99944ee4 100644 --- a/source/blender/python/BPY_interface.c +++ b/source/blender/python/BPY_interface.c @@ -1261,6 +1261,45 @@ int BPY_is_pyconstraint(Text *text) return 0; } +/* This function frees links from pyconstraints to a given text-buffer. + * Used when a text-buffer is unlinked! + */ +void BPY_free_pyconstraint_links(Text *text) +{ + Object *ob; + bConstraint *con; + short update; + + /*check all pyconstraints*/ + for (ob=G.main->object.first; ob; ob=ob->id.next) { + update = 0; + if(ob->type==OB_ARMATURE && ob->pose) { + bPoseChannel *pchan; + for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { + for (con = pchan->constraints.first; con; con=con->next) { + if (con->type==CONSTRAINT_TYPE_PYTHON) { + bPythonConstraint *data = con->data; + if (data->text==text) data->text = NULL; + update = 1; + + } + } + } + } + for (con = ob->constraints.first; con; con=con->next) { + if (con->type==CONSTRAINT_TYPE_PYTHON) { + bPythonConstraint *data = con->data; + if (data->text==text) data->text = NULL; + update = 1; + } + } + + if (update) { + DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); + } + } +} + /* This function is called to update PyConstraint data so that it is compatible with the script. * Some of the allocating/freeing of memory for constraint targets occurs here, espcially * if the number of targets changes. diff --git a/source/blender/python/api2_2x/Text.c b/source/blender/python/api2_2x/Text.c index 29c404f7266..6c577285266 100644 --- a/source/blender/python/api2_2x/Text.c +++ b/source/blender/python/api2_2x/Text.c @@ -1,5 +1,5 @@ /* - * $Id: Text.c 11123 2007-06-29 08:59:26Z campbellbarton $ + * $Id$ * * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** * @@ -289,6 +289,7 @@ static PyObject *M_Text_unlink( PyObject * self, PyObject * args ) "this text was already unlinked!" ); BPY_clear_bad_scriptlinks( text ); + BPY_free_pyconstraint_links( text ); free_text_controllers( text ); unlink_text( text ); diff --git a/source/blender/python/api2_2x/bpy_data.c b/source/blender/python/api2_2x/bpy_data.c index 8ad577bd175..3fb58146ca9 100644 --- a/source/blender/python/api2_2x/bpy_data.c +++ b/source/blender/python/api2_2x/bpy_data.c @@ -621,7 +621,7 @@ PyObject *LibBlockSeq_unlink(BPy_LibBlockSeq *self, PyObject * value) if (!data) return EXPP_ReturnPyObjError( PyExc_RuntimeError, - "This Group has been removed alredy" ); + "This Group has been removed already" ); /* Run the removal code */ free_group(data); @@ -642,10 +642,11 @@ PyObject *LibBlockSeq_unlink(BPy_LibBlockSeq *self, PyObject * value) if (!data) return EXPP_ReturnPyObjError( PyExc_RuntimeError, - "This Group has been removed alredy" ); + "This Group has been removed already" ); /* Run the removal code */ BPY_clear_bad_scriptlinks( data ); + BPY_free_pyconstraint_links( data ); free_text_controllers( data ); unlink_text( data ); free_libblock( &G.main->text, data ); diff --git a/source/blender/src/header_text.c b/source/blender/src/header_text.c index 728edc76a9c..ac7f4be9ec0 100644 --- a/source/blender/src/header_text.c +++ b/source/blender/src/header_text.c @@ -140,10 +140,6 @@ void do_text_buttons(unsigned short event) case B_TEXTDELETE: { - Object *obt; - bConstraint *con; - int update; - text= st->text; if (!text) return; @@ -156,36 +152,8 @@ void do_text_buttons(unsigned short event) pop_space_text(st); } - /*check all pyconstraints*/ - for (obt=G.main->object.first; obt; obt=obt->id.next) { - update = 0; - if(obt->type==OB_ARMATURE && obt->pose) { - bPoseChannel *pchan; - for(pchan= obt->pose->chanbase.first; pchan; pchan= pchan->next) { - for (con = pchan->constraints.first; con; con=con->next) { - if (con->type==CONSTRAINT_TYPE_PYTHON) { - bPythonConstraint *data = con->data; - if (data->text==text) data->text = NULL; - update = 1; - - } - } - } - } - for (con = obt->constraints.first; con; con=con->next) { - if (con->type==CONSTRAINT_TYPE_PYTHON) { - bPythonConstraint *data = con->data; - if (data->text==text) data->text = NULL; - update = 1; - } - } - - if (update) { - DAG_object_flush_update(G.scene, obt, OB_RECALC_DATA); - } - } - BPY_clear_bad_scriptlinks(text); + BPY_free_pyconstraint_links(text); free_text_controllers(text); unlink_text(text); -- cgit v1.2.3