join could crash blender in background mode or if the mesh was not in the current scene. added exceptions for both and notes in the EpyDocs.

This commit is contained in:
Campbell Barton 2006-06-26 02:43:15 +00:00
parent 9be8517ca3
commit a6fc975d49
2 changed files with 20 additions and 2 deletions

@ -2025,6 +2025,10 @@ static PyObject *Object_join( BPy_Object * self, PyObject * args )
short type;
int i, ok=0, ret_value=0, list_length=0;
if( G.background )
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"cannot join objects in background mode" ) );
/* Check if the arguments passed to makeParent are valid. */
if( !PyArg_ParseTuple( args, "O", &list ) )
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
@ -2049,12 +2053,16 @@ static PyObject *Object_join( BPy_Object * self, PyObject * args )
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
"Base object is not a type blender can join" ) );
if (object_in_scene( parent, G.scene )==NULL)
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
"object must be in the current scene" ) );
/* exit editmode so join can be done */
if( G.obedit )
exit_editmode( 1 );
temp_scene = add_scene( "Scene" ); /* make the new scene */
temp_scene->lay= 2097151; /* all layers on */
temp_scene->lay= 1; /* all layers on */
/* Check if the PyObject passed in list is a Blender object. */
for( i = 0; i < list_length; i++ ) {
@ -2069,6 +2077,13 @@ static PyObject *Object_join( BPy_Object * self, PyObject * args )
/* List item is an object, is it the same type? */
child = ( Object * ) Object_FromPyObject( py_child );
if (parent->type == child->type) {
if (object_in_scene( child, G.scene )==NULL) {
free_libblock( &G.main->scene, temp_scene );
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
"object must be in the current scene" ) );
}
ok =1;
/* Add a new base, then link the base to the temp_scene */
temp_base = MEM_callocN( sizeof( Base ), "pynewbase" );

@ -675,10 +675,13 @@ class Object:
@note: Join will only work for object types Mesh, Armature, Curve and Surface,
an error will be raised if the object is not of this type.
@note: objects in the list will be ignored if they to not match the base object.
@note: objects must be in the current scene to be joined.
@note: this function will not work in background mode (no user interface)
@note: An error in the join function input will raise a TypeError,
otherwise an error in the data input will raise a RuntimeError,
for situations where you don't have tight control on the data that is being joined,
you should handel the RuntimeError error, litting the user know the data cant be joined.
This an happen if the data is too large or one of the objects data has a shape key.
"""
def makeParentDeform(objects, noninverse = 0, fast = 0):