From 011203c45f7ce01e03ee90edd2b14ffcba627a97 Mon Sep 17 00:00:00 2001 From: Stephen Swaney Date: Tue, 11 Nov 2003 10:13:04 +0000 Subject: [PATCH] fixed the bug Joseph Gilbert found in numerous python files. newly created data objs had incorrect user counts. --- source/blender/python/api2_2x/Armature.c | 6 +++++- source/blender/python/api2_2x/Curve.c | 19 +++++++++-------- source/blender/python/api2_2x/Ipo.c | 26 ++++++++++++++++-------- source/blender/python/api2_2x/Metaball.c | 6 +++++- source/blender/python/api2_2x/Scene.c | 8 ++++++-- source/blender/python/api2_2x/Text.c | 6 +++++- source/blender/python/api2_2x/World.c | 10 ++++++--- 7 files changed, 56 insertions(+), 25 deletions(-) diff --git a/source/blender/python/api2_2x/Armature.c b/source/blender/python/api2_2x/Armature.c index 03322d678db..ccbc9b93324 100644 --- a/source/blender/python/api2_2x/Armature.c +++ b/source/blender/python/api2_2x/Armature.c @@ -52,8 +52,12 @@ static PyObject *M_Armature_New(PyObject *self, PyObject *args, "expected string(s) or empty argument")); 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); + } else return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't create Armature Data in Blender")); diff --git a/source/blender/python/api2_2x/Curve.c b/source/blender/python/api2_2x/Curve.c index ed91430e5ac..2587df53498 100644 --- a/source/blender/python/api2_2x/Curve.c +++ b/source/blender/python/api2_2x/Curve.c @@ -44,20 +44,23 @@ static PyObject *M_Curve_New(PyObject *self, PyObject *args) Curve *blcurve = 0; /* for actual Curve Data we create in Blender */ if (!PyArg_ParseTuple(args, "|s", &name)) - return (EXPP_ReturnPyObjError (PyExc_AttributeError, - "expected string argument or no argument")); + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected string argument or no argument")); blcurve = add_curve(OB_CURVE); /* first create the Curve Data in Blender */ - if (blcurve == NULL) - return (EXPP_ReturnPyObjError (PyExc_RuntimeError, - "couldn't create Curve Data in Blender")); + + if (blcurve == NULL) /* bail out if add_curve() failed */ + 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); - if (pycurve == NULL) - return (EXPP_ReturnPyObjError (PyExc_MemoryError, - "couldn't create Curve Data object")); + return (EXPP_ReturnPyObjError (PyExc_MemoryError, + "couldn't create Curve Data object")); pycurve->curve = blcurve; /* link Python curve wrapper to Blender Curve */ if (name) diff --git a/source/blender/python/api2_2x/Ipo.c b/source/blender/python/api2_2x/Ipo.c index 15117c39c9d..5bc5741d7be 100644 --- a/source/blender/python/api2_2x/Ipo.c +++ b/source/blender/python/api2_2x/Ipo.c @@ -45,19 +45,27 @@ static PyObject *M_Ipo_New(PyObject *self, PyObject *args) BPy_Ipo *pyipo; 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")); - if (!strcmp(code,"Object"))idcode = ID_OB; - if (!strcmp(code,"Camera"))idcode = ID_CA; - if (!strcmp(code,"World"))idcode = ID_WO; - if (!strcmp(code,"Material"))idcode = ID_MA; - if (idcode == -1) + + if (!strcmp(code,"Object"))idcode = ID_OB; + if (!strcmp(code,"Camera"))idcode = ID_CA; + if (!strcmp(code,"World"))idcode = ID_WO; + if (!strcmp(code,"Material"))idcode = ID_MA; + + if (idcode == -1) 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); - if (blipo) - pyipo = (BPy_Ipo *)PyObject_NEW(BPy_Ipo, &Ipo_Type); + if (blipo){ + /* 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 return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't create Ipo Data in Blender")); diff --git a/source/blender/python/api2_2x/Metaball.c b/source/blender/python/api2_2x/Metaball.c index dcf4a16b088..ca1348e2ffa 100644 --- a/source/blender/python/api2_2x/Metaball.c +++ b/source/blender/python/api2_2x/Metaball.c @@ -76,8 +76,12 @@ static PyObject *M_Metaball_New(PyObject *self, PyObject *args) 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); + } else return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't create MetaBall Data in Blender")); diff --git a/source/blender/python/api2_2x/Scene.c b/source/blender/python/api2_2x/Scene.c index 53bbf9f18fc..b675a9b0708 100644 --- a/source/blender/python/api2_2x/Scene.c +++ b/source/blender/python/api2_2x/Scene.c @@ -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 */ - if (blscene) /* now create the wrapper obj in Python */ - pyscene = Scene_CreatePyObject (blscene); + if (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 return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't create Scene obj in Blender")); diff --git a/source/blender/python/api2_2x/Text.c b/source/blender/python/api2_2x/Text.c index 41fd6c99f60..e2819de3bab 100644 --- a/source/blender/python/api2_2x/Text.c +++ b/source/blender/python/api2_2x/Text.c @@ -49,8 +49,12 @@ static PyObject *M_Text_New(PyObject *self, PyObject *args, PyObject *keywords) 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); + } else return EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't create Text Object in Blender"); diff --git a/source/blender/python/api2_2x/World.c b/source/blender/python/api2_2x/World.c index 5b488e1688b..ba3b3e1eea3 100644 --- a/source/blender/python/api2_2x/World.c +++ b/source/blender/python/api2_2x/World.c @@ -116,13 +116,17 @@ static PyObject *M_World_New(PyObject *self, PyObject *args, PyObject *kwords) if (!PyArg_ParseTuple(args, "s", &name)) return (EXPP_ReturnPyObjError (PyExc_TypeError, - "expected int argument")); + "expected int argument")); blworld = add_world(name); - if (blworld) - pyworld = (BPy_World *)PyObject_NEW(BPy_World, &World_Type); + if (blworld){ + /* 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 return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "couldn't create World Data in Blender"));