Fix #32734: Object.to_mesh() gave wrong user count for curves/surface/text objects.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 5 Oct 2012 12:18:09 +0000 (12:18 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 5 Oct 2012 12:18:09 +0000 (12:18 +0000)
source/blender/makesrna/intern/rna_object_api.c

index b0b76c9e38ff9b6cf68de75594644516c49e7a47..879a77527cd67348bde587eedb5f0eac4ed99fdf 100644 (file)
@@ -177,6 +177,8 @@ Mesh *rna_Object_to_mesh(Object *ob, ReportList *reports, Scene *sce, int apply_
                                return NULL;  /* only do basis metaball */
                        
                        tmpmesh = BKE_mesh_add("Mesh");
+                       /* BKE_mesh_add gives us a user count we don't need */
+                       tmpmesh->id.us--;
 
                        if (render) {
                                ListBase disp = {NULL, NULL};
@@ -186,6 +188,7 @@ Mesh *rna_Object_to_mesh(Object *ob, ReportList *reports, Scene *sce, int apply_
                        }
                        else
                                BKE_mesh_from_metaball(&ob->disp, tmpmesh);
+
                        break;
 
                }
@@ -214,6 +217,9 @@ Mesh *rna_Object_to_mesh(Object *ob, ReportList *reports, Scene *sce, int apply_
                                dm->release(dm);
                        }
 
+                       /* BKE_mesh_add/copy gives us a user count we don't need */
+                       tmpmesh->id.us--;
+
                        break;
                default:
                        BKE_report(reports, RPT_ERROR, "Object does not have geometry data");
@@ -283,9 +289,6 @@ Mesh *rna_Object_to_mesh(Object *ob, ReportList *reports, Scene *sce, int apply_
        /* cycles and exporters rely on this still */
        BKE_mesh_tessface_ensure(tmpmesh);
 
-       /* we don't assign it to anything */
-       tmpmesh->id.us--;
-       
        /* make sure materials get updated in objects */
        test_object_materials(&tmpmesh->id);