fixed the bug Joseph Gilbert found in numerous python files.
authorStephen Swaney <sswaney@centurytel.net>
Tue, 11 Nov 2003 10:13:04 +0000 (10:13 +0000)
committerStephen Swaney <sswaney@centurytel.net>
Tue, 11 Nov 2003 10:13:04 +0000 (10:13 +0000)
newly created data objs had incorrect user counts.

source/blender/python/api2_2x/Armature.c
source/blender/python/api2_2x/Curve.c
source/blender/python/api2_2x/Ipo.c
source/blender/python/api2_2x/Metaball.c
source/blender/python/api2_2x/Scene.c
source/blender/python/api2_2x/Text.c
source/blender/python/api2_2x/World.c

index 03322d678dbba6a868e80ad9d1ebb160d5fe4171..ccbc9b93324475b4f802f16f7e91f83d81f627c6 100644 (file)
@@ -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"));
index ed91430e5ac3a71149dbf206221ca1eb81eb672e..2587df5349872267de1f4fe84a6f8fcad8ba74fb 100644 (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 */
   
   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)
index 15117c39c9d30f31859008cb9dbb136335fa5c6a..5bc5741d7be178707fea26d1c904795566d5ed07 100644 (file)
@@ -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"));
index dcf4a16b088c621a2b01e4844abe41a2f16e4c1a..ca1348e2ffa6bb1529f277272c89e703be592084 100644 (file)
@@ -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"));
index 53bbf9f18fc0e55ccf328bba712451f233bd5ed4..b675a9b0708e2f5ce2656f863e98972b4319ba45 100644 (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 */
 
-       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"));
index 41fd6c99f60f96eb03c29b0d9a1d08d99edd3aaa..e2819de3babb0bacd52fa23720be7755a0916aef 100644 (file)
@@ -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");
index 5b488e1688b9f282eb1a468165932429c3f08359..ba3b3e1eea36cfeb4bae19f9636a588bc4e32ddc 100644 (file)
@@ -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"));