Fix collada importer doing own handling of usercount/freeing.
authorBastien Montagne <montagne29@wanadoo.fr>
Thu, 15 Jun 2017 10:44:15 +0000 (12:44 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Thu, 15 Jun 2017 10:44:15 +0000 (12:44 +0200)
Better use generic `BKE_libblock_free_us()`.

source/blender/collada/DocumentImporter.cpp
source/blender/collada/MeshImporter.cpp

index 226f319cefd7c8542beaaef1aa1a1b06dd6569fa..435eaa0208ab0ff5ce6501a39a100c3e60759477 100644 (file)
@@ -388,9 +388,7 @@ Object *DocumentImporter::create_camera_object(COLLADAFW::InstanceCamera *camera
        Camera *cam = uid_camera_map[cam_uid];
        Camera *old_cam = (Camera *)ob->data;
        ob->data = cam;
-       id_us_min(&old_cam->id);
-       if (old_cam->id.us == 0)
-               BKE_libblock_free(G.main, old_cam);
+       BKE_libblock_free_us(G.main, old_cam);
        return ob;
 }
 
@@ -406,9 +404,7 @@ Object *DocumentImporter::create_lamp_object(COLLADAFW::InstanceLight *lamp, Sce
        Lamp *la = uid_lamp_map[lamp_uid];
        Lamp *old_lamp = (Lamp *)ob->data;
        ob->data = la;
-       id_us_min(&old_lamp->id);
-       if (old_lamp->id.us == 0)
-               BKE_libblock_free(G.main, old_lamp);
+       BKE_libblock_free_us(G.main, old_lamp);
        return ob;
 }
 
index a1bfce8813176ea0e33166c309104aae7ef14eb5..6ca53c64299e75f89f98ed295b3b96a79792c261 100644 (file)
@@ -1173,8 +1173,9 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta
        BKE_mesh_assign_object(ob, new_mesh);
        BKE_mesh_calc_normals(new_mesh);
 
-       if (old_mesh->id.us == 0) BKE_libblock_free(G.main, old_mesh);
-       
+       id_us_plus(&old_mesh->id);  /* Because BKE_mesh_assign_object would have already decreased it... */
+       BKE_libblock_free_us(G.main, old_mesh);
+
        char layername[100];
        layername[0] = '\0';
        MTFace *texture_face = NULL;