Commit: 4dac0afa9ca47444f3222a9833e74f970c58c85a
Author: Bastien Montagne
Date:   Tue Oct 13 15:48:18 2015 +0200
Branches: missing-libs
https://developer.blender.org/rB4dac0afa9ca47444f3222a9833e74f970c58c85a

Merge branch 'free-refcount-ids' into missing-libs

===================================================================



===================================================================

diff --cc source/blender/blenkernel/BKE_curve.h
index 4ac5629,a03dd28..061270b
--- a/source/blender/blenkernel/BKE_curve.h
+++ b/source/blender/blenkernel/BKE_curve.h
@@@ -66,9 -66,9 +66,10 @@@ typedef struct CurveCache 
  #define CU_DO_2DFILL(cu)  ((((cu)->flag & CU_3D) == 0) && (((cu)->flag & 
(CU_FRONT | CU_BACK)) != 0))
  
  /* ** Curve ** */
- void BKE_curve_free(struct Curve *cu, const bool do_id_user);
+ void BKE_curve_unlink(struct Curve *cu);
+ void BKE_curve_free(struct Curve *cu);
  void BKE_curve_editfont_free(struct Curve *cu);
 +void BKE_curve_init(struct Curve *cu);
  struct Curve *BKE_curve_add(struct Main *bmain, const char *name, int type);
  struct Curve *BKE_curve_copy(struct Curve *cu);
  void BKE_curve_make_local(struct Curve *cu);
diff --cc source/blender/blenkernel/BKE_lattice.h
index d4fa9af,677d8e3..828a40d
--- a/source/blender/blenkernel/BKE_lattice.h
+++ b/source/blender/blenkernel/BKE_lattice.h
@@@ -45,10 -45,9 +45,10 @@@ struct BPoint
  struct MDeformVert;
  
  void BKE_lattice_resize(struct Lattice *lt, int u, int v, int w, struct 
Object *ltOb);
 +void BKE_lattice_init(struct Lattice *lt);
  struct Lattice *BKE_lattice_add(struct Main *bmain, const char *name);
  struct Lattice *BKE_lattice_copy(struct Lattice *lt);
- void BKE_lattice_free(struct Lattice *lt, const bool do_id_user);
+ void BKE_lattice_free(struct Lattice *lt);
  void BKE_lattice_make_local(struct Lattice *lt);
  void calc_lat_fudu(int flag, int res, float *r_fu, float *r_du);
  
diff --cc source/blender/blenkernel/BKE_linestyle.h
index 76e64d4,e77b4f5..e3eead4
--- a/source/blender/blenkernel/BKE_linestyle.h
+++ b/source/blender/blenkernel/BKE_linestyle.h
@@@ -49,9 -49,8 +49,9 @@@ struct Object
  struct ColorBand;
  struct bContext;
  
 +void BKE_linestyle_init(struct FreestyleLineStyle *linestyle);
  FreestyleLineStyle *BKE_linestyle_new(struct Main *bmain, const char *name);
- void                BKE_linestyle_free(FreestyleLineStyle *linestyle, const 
bool do_id_user);
+ void                BKE_linestyle_free(FreestyleLineStyle *linestyle);
  FreestyleLineStyle *BKE_linestyle_copy(struct Main *bmain, FreestyleLineStyle 
*linestyle);
  
  FreestyleLineStyle *BKE_linestyle_active_from_scene(struct Scene *scene);
diff --cc source/blender/blenkernel/BKE_material.h
index 22b71be,a3c61f4..b85f9e5
--- a/source/blender/blenkernel/BKE_material.h
+++ b/source/blender/blenkernel/BKE_material.h
@@@ -45,10 -45,11 +45,11 @@@ struct Scene
  /* materials */
  
  void init_def_material(void);
- void BKE_material_free(struct Material *ma, const bool do_id_user);
+ void BKE_material_free(struct Material *sc); 
+ void BKE_material_free_ex(struct Material *ma, bool do_id_user);
  void test_object_materials(struct Main *bmain, struct ID *id);
  void BKE_material_resize_object(struct Object *ob, const short totcol, bool 
do_id_user);
 -void init_material(struct Material *ma);
 +void BKE_init_material(struct Material *ma);
  void BKE_material_remap_object(struct Object *ob, const unsigned int *remap);
  struct Material *BKE_material_add(struct Main *bmain, const char *name);
  struct Material *BKE_material_copy(struct Material *ma);
diff --cc source/blender/blenkernel/BKE_mball.h
index b09d815,62cd500..0574b88
--- a/source/blender/blenkernel/BKE_mball.h
+++ b/source/blender/blenkernel/BKE_mball.h
@@@ -38,8 -38,8 +38,9 @@@ struct Object
  struct Scene;
  struct MetaElem;
  
- void BKE_mball_free(struct MetaBall *mb, const bool do_id_user);
+ void BKE_mball_unlink(struct MetaBall *mb);
+ void BKE_mball_free(struct MetaBall *mb);
 +void BKE_mball_init(struct MetaBall *mb);
  struct MetaBall *BKE_mball_add(struct Main *bmain, const char *name);
  struct MetaBall *BKE_mball_copy(struct MetaBall *mb);
  
diff --cc source/blender/blenkernel/BKE_mesh.h
index 19d44c6,5bd8931..f35613f
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@@ -80,8 -80,8 +80,9 @@@ int poly_get_adj_loops_from_vert
  
  int BKE_mesh_edge_other_vert(const struct MEdge *e, int v);
  
- void BKE_mesh_free(struct Mesh *me, const bool do_id_user);
+ void BKE_mesh_unlink(struct Mesh *me);
+ void BKE_mesh_free(struct Mesh *me, int unlink);
 +void BKE_mesh_init(struct Mesh *me);
  struct Mesh *BKE_mesh_add(struct Main *bmain, const char *name);
  struct Mesh *BKE_mesh_copy_ex(struct Main *bmain, struct Mesh *me);
  struct Mesh *BKE_mesh_copy(struct Mesh *me);
diff --cc source/blender/blenkernel/BKE_scene.h
index 14c7ace,027bdbb..aa69831
--- a/source/blender/blenkernel/BKE_scene.h
+++ b/source/blender/blenkernel/BKE_scene.h
@@@ -66,8 -66,7 +66,8 @@@ struct Base *_setlooper_base_step(struc
  void free_avicodecdata(struct AviCodecData *acd);
  void free_qtcodecdata(struct QuicktimeCodecData *acd);
  
- void BKE_scene_free(struct Scene *sce, const bool do_id_user);
+ void BKE_scene_free(struct Scene *sce);
 +void BKE_scene_init(struct Scene *sce);
  struct Scene *BKE_scene_add(struct Main *bmain, const char *name);
  
  /* base functions */
diff --cc source/blender/blenkernel/BKE_text.h
index 71a6a7d,a5a59d1..50e4fa4
--- a/source/blender/blenkernel/BKE_text.h
+++ b/source/blender/blenkernel/BKE_text.h
@@@ -41,10 -41,9 +41,10 @@@ struct Main
  struct Text;
  struct TextLine;
  
- void                  BKE_text_free           (struct Text *text, const bool 
do_id_user);
+ void                  BKE_text_free           (struct Text *text);
  void                  txt_set_undostate       (int u);
  int                   txt_get_undostate       (void);
 +void            BKE_text_init(struct Text *ta);
  struct Text    *BKE_text_add  (struct Main *bmain, const char *name);
  int                           txt_extended_ascii_as_utf8(char **str);
  bool            BKE_text_reload(struct Text *text);
diff --cc source/blender/blenkernel/BKE_world.h
index 7d3c56f,7f4ba6c..8d7ab23
--- a/source/blender/blenkernel/BKE_world.h
+++ b/source/blender/blenkernel/BKE_world.h
@@@ -36,8 -36,8 +36,9 @@@
  struct Main;
  struct World;
  
- void BKE_world_free(struct World *sc, const bool do_id_user);
+ void BKE_world_free(struct World *sc);
+ void BKE_world_free_ex(struct World *sc, bool do_id_user);
 +void BKE_world_init(struct World *wrld);
  struct World *add_world(struct Main *bmian, const char *name);
  struct World *BKE_world_copy(struct World *wrld);
  struct World *localize_world(struct World *wrld);
diff --cc source/blender/blenkernel/intern/curve.c
index ce1392c,8d7d62b..8eed1f4
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@@ -161,18 -146,26 +146,25 @@@ void BKE_curve_free(Curve *cu
        BKE_curve_editfont_free(cu);
  
        BKE_curve_editNurb_free(cu);
+       BKE_curve_unlink(cu);
+       BKE_animdata_free((ID *)cu);
  
-       MEM_SAFE_FREE(cu->mat);
-       MEM_SAFE_FREE(cu->str);
-       MEM_SAFE_FREE(cu->strinfo);
-       MEM_SAFE_FREE(cu->bb);
-       MEM_SAFE_FREE(cu->tb);
+       if (cu->mat)
+               MEM_freeN(cu->mat);
+       if (cu->str)
+               MEM_freeN(cu->str);
+       if (cu->strinfo)
+               MEM_freeN(cu->strinfo);
+       if (cu->bb)
+               MEM_freeN(cu->bb);
+       if (cu->tb)
+               MEM_freeN(cu->tb);
  }
  
 -Curve *BKE_curve_add(Main *bmain, const char *name, int type)
 +void BKE_curve_init(Curve *cu)
  {
 -      Curve *cu;
 +      BLI_assert(MEMCMP_NULL_STRUCT_OFS(cu, id));
  
 -      cu = BKE_libblock_alloc(bmain, ID_CU, name);
        copy_v3_fl(cu->size, 1.0f);
        cu->flag = CU_FRONT | CU_BACK | CU_DEFORM_BOUNDS_OFF | CU_PATH_RADIUS;
        cu->pathlen = 100;
diff --cc source/blender/blenkernel/intern/material.c
index 4cff6d4,3e7e98b..a43906c
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@@ -78,63 -78,52 +78,54 @@@ Material defmaterial
  /* called on startup, creator.c */
  void init_def_material(void)
  {
 -      init_material(&defmaterial);
 +      BKE_init_material(&defmaterial);
  }
  
- /**
-  * Free (or release) any data used by this material (does not free the 
material itself).
-  *
-  * \param ma The material to free.
-  * \param do_id_user When \a true, ID datablocks used (referenced) by this 
material are 'released'
-  *                   (their user count is decreased).
-  */
- void BKE_material_free(Material *ma, const bool do_id_user)
+ /* not material itself */
+ void BKE_material_free(Material *ma)
  {
-       int a;
- 
-       if (do_id_user)  {
-               MTex *mtex;
- 
-               for (a = 0; a < MAX_MTEX; a++) {
-                       mtex = ma->mtex[a];
-                       if (mtex && mtex->tex) {
-                               id_us_min(&mtex->tex->id);
-                               mtex->tex = NULL;
-                       }
-               }
- 
-               /* No ID refcount here... */
-               ma->group = NULL;
-       }
+       BKE_material_free_ex(ma, true);
+ }
  
-       BKE_animdata_free((ID *)ma);
+ /* not material itself */
+ void BKE_material_free_ex(Material *ma, bool do_id_user)
+ {
+       MTex *mtex;
+       int a;
        
        for (a = 0; a < MAX_MTEX; a++) {
-               MEM_SAFE_FREE(ma->mtex[a]);
+               mtex = ma->mtex[a];
+               if (do_id_user && mtex && mtex->tex) mtex->tex->id.us--;
+               if (mtex) MEM_freeN(mtex);
        }
        
-       MEM_SAFE_FREE(ma->ramp_col);
-       MEM_SAFE_FREE(ma->ramp_spec);
+       if (ma->ramp_col) MEM_freeN(ma->ramp_col);
+       if (ma->ramp_spec) MEM_freeN(ma->ramp_spec);
+       
+       BKE_animdata_free((ID *)ma);
+       
+       if (ma->preview)
+               BKE_previewimg_free(&ma->preview);
+       BKE_icon_id_delete((struct ID *)ma);
+       ma->id.icon_id = 0;
        
        /* is no lib link block, but material extension */
        if (ma->nodetree) {
-               ntreeFreeTree(ma->nodetree, do_id_user);
+               ntreeFreeTree_ex(ma->nodetree, do_id_user);
                MEM_freeN(ma->nodetree);
-               ma->nodetree = NULL;
        }
  
-       MEM_SAFE_FREE(ma->texpaintslot);
- 
-       GPU_material_free(&ma->gpumaterial);
+       if (ma->texpaintslot)
+               MEM_freeN(ma->texpaintslot);
  
-       BKE_icon_id_delete((ID *)ma);
-       BKE_previewimg_free(&ma->preview);
+       if (ma->gpumaterial.first)
+               GPU_material_free(&ma->gpumaterial);
  }
  
 -void init_material(Material *ma)
 +void BKE_init_material(Material *ma)
  {
 +      BLI_assert(MEMCMP_NULL_STRUCT_OFS(ma, id));
 +
        ma->r = ma->g = ma->b = ma->ref = 0.8;
        ma->specr = ma->specg = ma->specb = 1.0;
        ma->mirr = ma->mirg = ma->mirb = 1.0;
diff --cc source/blender/blenkernel/intern/mball.c
index 50c063e,c09cd1a..48f1a1a
--- a/source/blender/blenkernel/intern/mball.c
+++ b/source/blender/blenkernel/intern/mball.c
@@@ -66,41 -66,40 +66,38 @@@
  
  /* Functions */
  
- /**
-  * Free (or release) any data used by this mball (does not free the mball 
itself).
-  *
-  * \param mb The mball to

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to