fixed the bug Joseph Gilbert found in numerous python files.

newly created data objs had incorrect user counts.
This commit is contained in:
Stephen Swaney
2003-11-11 10:13:04 +00:00
parent 1018943b3d
commit 011203c45f
7 changed files with 56 additions and 25 deletions

View File

@@ -52,8 +52,12 @@ static PyObject *M_Armature_New(PyObject *self, PyObject *args,
"expected string(s) or empty argument")); "expected string(s) or empty argument"));
bl_armature = add_armature(); /* first create in Blender */ bl_armature = add_armature(); /* first create in Blender */
if (bl_armature) /* now create the wrapper obj in Python */ if (bl_armature){
/* return user count to zero because add_armature() inc'd it */
bl_armature->id.us = 0;
/* now create the wrapper obj in Python */
py_armature = (BPy_Armature *)PyObject_NEW(BPy_Armature, &Armature_Type); py_armature = (BPy_Armature *)PyObject_NEW(BPy_Armature, &Armature_Type);
}
else else
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't create Armature Data in Blender")); "couldn't create Armature Data in Blender"));

View File

@@ -44,20 +44,23 @@ static PyObject *M_Curve_New(PyObject *self, PyObject *args)
Curve *blcurve = 0; /* for actual Curve Data we create in Blender */ Curve *blcurve = 0; /* for actual Curve Data we create in Blender */
if (!PyArg_ParseTuple(args, "|s", &name)) if (!PyArg_ParseTuple(args, "|s", &name))
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected string argument or no argument")); "expected string argument or no argument"));
blcurve = add_curve(OB_CURVE); /* first create the Curve Data in Blender */ blcurve = add_curve(OB_CURVE); /* first create the Curve Data in Blender */
if (blcurve == NULL)
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, if (blcurve == NULL) /* bail out if add_curve() failed */
"couldn't create Curve Data in Blender")); return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't create Curve Data in Blender"));
/* return user count to zero because add_curve() inc'd it */
blcurve->id.us = 0;
/* create python wrapper obj */
pycurve = (BPy_Curve *)PyObject_NEW(BPy_Curve, &Curve_Type); pycurve = (BPy_Curve *)PyObject_NEW(BPy_Curve, &Curve_Type);
if (pycurve == NULL) if (pycurve == NULL)
return (EXPP_ReturnPyObjError (PyExc_MemoryError, return (EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create Curve Data object")); "couldn't create Curve Data object"));
pycurve->curve = blcurve; /* link Python curve wrapper to Blender Curve */ pycurve->curve = blcurve; /* link Python curve wrapper to Blender Curve */
if (name) if (name)

View File

@@ -45,19 +45,27 @@ static PyObject *M_Ipo_New(PyObject *self, PyObject *args)
BPy_Ipo *pyipo; BPy_Ipo *pyipo;
Ipo *blipo; Ipo *blipo;
if (!PyArg_ParseTuple(args, "ss", &code,&name)) if (!PyArg_ParseTuple(args, "ss", &code,&name))
return (EXPP_ReturnPyObjError (PyExc_TypeError,"expected string int arguments")); return (EXPP_ReturnPyObjError (PyExc_TypeError,"expected string int arguments"));
if (!strcmp(code,"Object"))idcode = ID_OB;
if (!strcmp(code,"Camera"))idcode = ID_CA; if (!strcmp(code,"Object"))idcode = ID_OB;
if (!strcmp(code,"World"))idcode = ID_WO; if (!strcmp(code,"Camera"))idcode = ID_CA;
if (!strcmp(code,"Material"))idcode = ID_MA; if (!strcmp(code,"World"))idcode = ID_WO;
if (idcode == -1) if (!strcmp(code,"Material"))idcode = ID_MA;
if (idcode == -1)
return (EXPP_ReturnPyObjError (PyExc_TypeError,"Bad code")); return (EXPP_ReturnPyObjError (PyExc_TypeError,"Bad code"));
printf("%d %d %d \n", ID_OB, ID_CA, ID_WO);
printf("%d %d %d \n", ID_OB, ID_CA, ID_WO);
blipo = add_ipo(name,idcode); blipo = add_ipo(name,idcode);
if (blipo) if (blipo){
pyipo = (BPy_Ipo *)PyObject_NEW(BPy_Ipo, &Ipo_Type); /* return user count to zero because add_ipo() inc'd it */
blipo->id.us = 0;
/* create python wrapper obj */
pyipo = (BPy_Ipo *)PyObject_NEW(BPy_Ipo, &Ipo_Type);
}
else else
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't create Ipo Data in Blender")); "couldn't create Ipo Data in Blender"));

View File

@@ -76,8 +76,12 @@ static PyObject *M_Metaball_New(PyObject *self, PyObject *args)
blmball = add_mball(); /* first create the MetaBall Data in Blender */ blmball = add_mball(); /* first create the MetaBall Data in Blender */
if (blmball) /* now create the wrapper obj in Python */ if (blmball){
/* return user count to zero since add_mball() incref'ed it */
blmball->id.us = 0;
/* now create the wrapper obj in Python */
pymball = (BPy_Metaball *)PyObject_NEW(BPy_Metaball, &Metaball_Type); pymball = (BPy_Metaball *)PyObject_NEW(BPy_Metaball, &Metaball_Type);
}
else else
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't create MetaBall Data in Blender")); "couldn't create MetaBall Data in Blender"));

View File

@@ -229,8 +229,12 @@ static PyObject *M_Scene_New(PyObject *self, PyObject *args, PyObject *kword)
blscene = add_scene(name); /* first create the Scene in Blender */ blscene = add_scene(name); /* first create the Scene in Blender */
if (blscene) /* now create the wrapper obj in Python */ if (blscene){
pyscene = Scene_CreatePyObject (blscene); /* return user count to zero because add_scene() inc'd it */
blscene->id.us = 0;
/* now create the wrapper obj in Python */
pyscene = Scene_CreatePyObject (blscene);
}
else else
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't create Scene obj in Blender")); "couldn't create Scene obj in Blender"));

View File

@@ -49,8 +49,12 @@ static PyObject *M_Text_New(PyObject *self, PyObject *args, PyObject *keywords)
bl_text = add_empty_text(); bl_text = add_empty_text();
if (bl_text) if (bl_text) {
/* return user count to zero because add_empty_text() inc'd it */
bl_text->id.us = 0;
/* create python wrapper obj */
py_text = Text_CreatePyObject (bl_text); py_text = Text_CreatePyObject (bl_text);
}
else else
return EXPP_ReturnPyObjError (PyExc_RuntimeError, return EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't create Text Object in Blender"); "couldn't create Text Object in Blender");

View File

@@ -116,13 +116,17 @@ static PyObject *M_World_New(PyObject *self, PyObject *args, PyObject *kwords)
if (!PyArg_ParseTuple(args, "s", &name)) if (!PyArg_ParseTuple(args, "s", &name))
return (EXPP_ReturnPyObjError (PyExc_TypeError, return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected int argument")); "expected int argument"));
blworld = add_world(name); blworld = add_world(name);
if (blworld) if (blworld){
pyworld = (BPy_World *)PyObject_NEW(BPy_World, &World_Type); /* return user count to zero because add_world() inc'd it */
blworld->id.us = 0;
/* create python wrapper obj */
pyworld = (BPy_World *)PyObject_NEW(BPy_World, &World_Type);
}
else else
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't create World Data in Blender")); "couldn't create World Data in Blender"));