Skip to content
Snippets Groups Projects
Commit 5f26e16c authored by Willian Padovani Germano's avatar Willian Padovani Germano
Browse files

Exppython: fixed crash caused by linking to a scene objects with NULL obdata,...

Exppython: fixed crash caused by linking to a scene objects with NULL obdata, caused by recent (2.28c) internal changes to avoid unneded creation of obdata.
parent 6c9f9d07
No related branches found
No related tags found
No related merge requests found
...@@ -531,15 +531,11 @@ static PyObject *Object_clrParent (BPy_Object *self, PyObject *args) ...@@ -531,15 +531,11 @@ static PyObject *Object_clrParent (BPy_Object *self, PyObject *args)
return (Py_None); return (Py_None);
} }
static PyObject *Object_getData (BPy_Object *self) /* adds object data to a Blender object, if object->data = NULL */
int EXPP_add_obdata(struct Object *object)
{ {
PyObject * data_object; if (object->data != NULL) return -1;
Object * object = self->object;
/* If there's no data associated to the Object, then there's nothing to */
/* return. */
if (object->data == NULL)
{
switch(object->type) switch(object->type)
{ {
case OB_ARMATURE: case OB_ARMATURE:
...@@ -587,6 +583,24 @@ static PyObject *Object_getData (BPy_Object *self) ...@@ -587,6 +583,24 @@ static PyObject *Object_getData (BPy_Object *self)
break; break;
*/ */
default: default:
break;
}
if (!object->data) return -1;
return 0;
}
static PyObject *Object_getData (BPy_Object *self)
{
PyObject * data_object;
Object * object = self->object;
/* if there's no obdata, try to create it */
if (object->data == NULL)
{
if (EXPP_add_obdata(object) != 0)
{ /* couldn't create obdata */
Py_INCREF (Py_None); Py_INCREF (Py_None);
return (Py_None); return (Py_None);
} }
......
...@@ -73,4 +73,6 @@ typedef struct { ...@@ -73,4 +73,6 @@ typedef struct {
struct Object * object; struct Object * object;
} BPy_Object; } BPy_Object;
int EXPP_add_obdata(struct Object *object);
#endif /* EXPP_OBJECT_H */ #endif /* EXPP_OBJECT_H */
...@@ -594,6 +594,10 @@ static PyObject *Scene_link (BPy_Scene *self, PyObject *args) ...@@ -594,6 +594,10 @@ static PyObject *Scene_link (BPy_Scene *self, PyObject *args)
return EXPP_ReturnPyObjError (PyExc_MemoryError, return EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't allocate new Base for object"); "couldn't allocate new Base for object");
/* check if this object has obdata, case not, try to create it */
if (!object->data && (object->type != OB_EMPTY))
EXPP_add_obdata(object); /* returns -1 on error, defined in Object.c */
base->object = object; /* link object to the new base */ base->object = object; /* link object to the new base */
base->lay = object->lay; base->lay = object->lay;
base->flag = object->flag; base->flag = object->flag;
......
...@@ -15,13 +15,25 @@ Example:: ...@@ -15,13 +15,25 @@ Example::
camdata = Camera.New('ortho') # create new camera data camdata = Camera.New('ortho') # create new camera data
camdata.setName('newCam') camdata.setName('newCam')
camdata.setLens(16.0) camdata.setLens(16.0)
camobj = Object.New('Camera') # create a new camera object
camobj.link(camdata) # link data to object
scene = Scene.New('NewScene') # create a new scene scene = Scene.New('NewScene') # create a new scene
scene.link(camobj) # link object to scene camobj = Object.New('Camera') # create a new camera object
camobj.link(camdata) # (*) link data to object first
scene.link(camobj) # and then link object to scene
scene.frameSettings(1, 100 ,1) # set start, end and current frames scene.frameSettings(1, 100 ,1) # set start, end and current frames
scene.setWinSize(640, 480) # set the render window dimensions scene.setWinSize(640, 480) # set the render window dimensions
scene.makeCurrent() # make this the current scene scene.makeCurrent() # make this the current scene
@warn: as done in the example (*), it's recommended to first link object data to
objects and only after that link objects to scene. This is because if
there is no object data linked to an object ob, scene.link(ob) will
automatically create the missing data. This is ok on its own, but I{if
after that} this object is linked to obdata, the automatically created one
will be discarded -- as expected -- but will stay in Blender's memory
space until the program is exited, since Blender doesn't really get rid of
most kinds of data. So first linking obdata to object, then object to
scene is a tiny tiny bit faster than the other way around and also saves
some realtime memory (if many objects are created from scripts, the
savings become important).
""" """
def New (name = 'Scene'): def New (name = 'Scene'):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment