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.
This commit is contained in:
2008-02-24 06:38:42 +00:00
parent c8569c934a
commit cd934aa1a8
5 changed files with 46 additions and 36 deletions

View File

@@ -79,6 +79,7 @@ extern "C" {
void BPY_pyconstraint_target(struct bPythonConstraint *con, struct bConstraintTarget *ct); void BPY_pyconstraint_target(struct bPythonConstraint *con, struct bConstraintTarget *ct);
void BPY_pyconstraint_update(struct Object *owner, struct bConstraint *con); void BPY_pyconstraint_update(struct Object *owner, struct bConstraint *con);
int BPY_is_pyconstraint(struct Text *text); 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_start_python( int argc, char **argv );
void BPY_end_python( void ); void BPY_end_python( void );

View File

@@ -1261,6 +1261,45 @@ int BPY_is_pyconstraint(Text *text)
return 0; 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. /* 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 * Some of the allocating/freeing of memory for constraint targets occurs here, espcially
* if the number of targets changes. * if the number of targets changes.

View File

@@ -1,5 +1,5 @@
/* /*
* $Id: Text.c 11123 2007-06-29 08:59:26Z campbellbarton $ * $Id$
* *
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
* *
@@ -289,6 +289,7 @@ static PyObject *M_Text_unlink( PyObject * self, PyObject * args )
"this text was already unlinked!" ); "this text was already unlinked!" );
BPY_clear_bad_scriptlinks( text ); BPY_clear_bad_scriptlinks( text );
BPY_free_pyconstraint_links( text );
free_text_controllers( text ); free_text_controllers( text );
unlink_text( text ); unlink_text( text );

View File

@@ -621,7 +621,7 @@ PyObject *LibBlockSeq_unlink(BPy_LibBlockSeq *self, PyObject * value)
if (!data) if (!data)
return EXPP_ReturnPyObjError( PyExc_RuntimeError, return EXPP_ReturnPyObjError( PyExc_RuntimeError,
"This Group has been removed alredy" ); "This Group has been removed already" );
/* Run the removal code */ /* Run the removal code */
free_group(data); free_group(data);
@@ -642,10 +642,11 @@ PyObject *LibBlockSeq_unlink(BPy_LibBlockSeq *self, PyObject * value)
if (!data) if (!data)
return EXPP_ReturnPyObjError( PyExc_RuntimeError, return EXPP_ReturnPyObjError( PyExc_RuntimeError,
"This Group has been removed alredy" ); "This Group has been removed already" );
/* Run the removal code */ /* Run the removal code */
BPY_clear_bad_scriptlinks( data ); BPY_clear_bad_scriptlinks( data );
BPY_free_pyconstraint_links( data );
free_text_controllers( data ); free_text_controllers( data );
unlink_text( data ); unlink_text( data );
free_libblock( &G.main->text, data ); free_libblock( &G.main->text, data );

View File

@@ -140,10 +140,6 @@ void do_text_buttons(unsigned short event)
case B_TEXTDELETE: case B_TEXTDELETE:
{ {
Object *obt;
bConstraint *con;
int update;
text= st->text; text= st->text;
if (!text) return; if (!text) return;
@@ -156,36 +152,8 @@ void do_text_buttons(unsigned short event)
pop_space_text(st); 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_clear_bad_scriptlinks(text);
BPY_free_pyconstraint_links(text);
free_text_controllers(text); free_text_controllers(text);
unlink_text(text); unlink_text(text);