[Bf-blender-cvs] [d5f35c6] id-remap: Merge branch 'free-refcount-ids' into id-remap

Bastien Montagne noreply at git.blender.org
Sat Oct 3 19:22:43 CEST 2015


Commit: d5f35c6c4e2faa30923e1c77de95554813d61fd5
Author: Bastien Montagne
Date:   Sat Oct 3 19:22:35 2015 +0200
Branches: id-remap
https://developer.blender.org/rBd5f35c6c4e2faa30923e1c77de95554813d61fd5

Merge branch 'free-refcount-ids' into id-remap

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



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

diff --cc source/blender/blenkernel/BKE_font.h
index 7751de8,18bc22b..449e656
--- a/source/blender/blenkernel/BKE_font.h
+++ b/source/blender/blenkernel/BKE_font.h
@@@ -78,8 -78,7 +78,8 @@@ bool BKE_vfont_is_builtin(struct VFont 
  void BKE_vfont_builtin_register(void *mem, int size);
  
  void BKE_vfont_free_data(struct VFont *vfont);
- void BKE_vfont_free(struct VFont *sc); 
+ void BKE_vfont_free(struct VFont *sc, const bool do_id_user);
 +void BKE_vfont_init(struct VFont *vfont);
  struct VFont *BKE_vfont_builtin_get(void);
  struct VFont *BKE_vfont_load(struct Main *bmain, const char *name);
  
diff --cc source/blender/blenkernel/BKE_lattice.h
index 828a40d,8f2f89f..3e7db65
--- a/source/blender/blenkernel/BKE_lattice.h
+++ b/source/blender/blenkernel/BKE_lattice.h
@@@ -45,10 -45,10 +45,11 @@@ 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);
+ void BKE_lattice_release_datablocks(struct Lattice *lt);
+ void BKE_lattice_free(struct Lattice *lt, const bool do_id_user);
  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 e3eead4,49b568a..c3fc00f
--- a/source/blender/blenkernel/BKE_linestyle.h
+++ b/source/blender/blenkernel/BKE_linestyle.h
@@@ -49,9 -49,9 +49,10 @@@ 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);
+ void                BKE_linestyle_release_datablocks(FreestyleLineStyle *linestyle);
+ void                BKE_linestyle_free(FreestyleLineStyle *linestyle, const bool do_id_user);
  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 b85f9e5,dda427e..98261cc
--- a/source/blender/blenkernel/BKE_material.h
+++ b/source/blender/blenkernel/BKE_material.h
@@@ -45,11 -45,11 +45,11 @@@ struct Scene
  /* materials */
  
  void init_def_material(void);
- void BKE_material_free(struct Material *sc); 
- void BKE_material_free_ex(struct Material *ma, bool do_id_user);
+ void BKE_material_release_datablocks(struct Material *ma);
+ void BKE_material_free(struct Material *ma, const 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_scene.h
index aa69831,78e22c1..ebe993b
--- a/source/blender/blenkernel/BKE_scene.h
+++ b/source/blender/blenkernel/BKE_scene.h
@@@ -66,8 -66,8 +66,9 @@@ 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);
+ void BKE_scene_release_datablocks(struct Scene *sce);
+ void BKE_scene_free(struct Scene *sce, const bool do_id_user);
 +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 50e4fa4,6350563..71a6a7d
--- 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);
+ void			BKE_text_free		(struct Text *text, const bool do_id_user);
  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 8d7ab23,422feb6..32d8960
--- a/source/blender/blenkernel/BKE_world.h
+++ b/source/blender/blenkernel/BKE_world.h
@@@ -36,9 -36,8 +36,9 @@@
  struct Main;
  struct World;
  
- void BKE_world_free(struct World *sc);
- void BKE_world_free_ex(struct World *sc, bool do_id_user);
+ void BKE_world_release_datablocks(struct World *wrld);
+ void BKE_world_free(struct World *sc, const 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 dafea12,c4296a2..1682f4a
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@@ -161,38 -170,20 +170,19 @@@ void BKE_curve_free(Curve *cu, const bo
  
  	BKE_curve_editNurb_free(cu);
  
- 	if (do_id_user) {
- 		BKE_curve_release_datablocks(cu);
- 	}
- 
  	BKE_animdata_free((ID *)cu);
  
- 	if (cu->mat) {
- 		MEM_freeN(cu->mat);
- 		cu->mat = NULL;
- 	}
- 	if (cu->str) {
- 		MEM_freeN(cu->str);
- 		cu->str = NULL;
- 	}
- 	if (cu->strinfo) {
- 		MEM_freeN(cu->strinfo);
- 		cu->strinfo = NULL;
- 	}
- 	if (cu->bb) {
- 		MEM_freeN(cu->bb);
- 		cu->bb = NULL;
- 	}
- 	if (cu->tb) {
- 		MEM_freeN(cu->tb);
- 		cu->tb = NULL;
- 	}
+ 	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);
  }
  
 -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 a43906c,27d4761..30fb694
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@@ -78,54 -78,72 +78,74 @@@ Material defmaterial
  /* called on startup, creator.c */
  void init_def_material(void)
  {
 -	init_material(&defmaterial);
 +	BKE_init_material(&defmaterial);
  }
  
- /* not material itself */
- void BKE_material_free(Material *ma)
+ /**
+  * Release all datablocks (ID) used by this material (datablocks are never freed, they are just unreferenced).
+  *
+  * \param ma The material which has to release its data.
+  */
+ void BKE_material_release_datablocks(Material *ma)
  {
- 	BKE_material_free_ex(ma, true);
+ 	MTex *mtex;
+ 	int a;
+ 
+ 	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;
  }
  
- /* not material itself */
- void BKE_material_free_ex(Material *ma, bool do_id_user)
+ /**
+  * 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)
  {
- 	MTex *mtex;
  	int a;
- 	
+ 
+ 	if (do_id_user)	 {
+ 		BKE_material_release_datablocks(ma);
+ 	}
+ 
  	for (a = 0; a < MAX_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->mtex[a]);
  	}
  	
- 	if (ma->ramp_col) MEM_freeN(ma->ramp_col);
- 	if (ma->ramp_spec) MEM_freeN(ma->ramp_spec);
+ 	MEM_SAFE_FREE(ma->ramp_col);
+ 	MEM_SAFE_FREE(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_ex(ma->nodetree, do_id_user);
+ 		ntreeFreeTree(ma->nodetree, do_id_user);
  		MEM_freeN(ma->nodetree);
+ 		ma->nodetree = NULL;
  	}
  
- 	if (ma->texpaintslot)
- 		MEM_freeN(ma->texpaintslot);
+ 	MEM_SAFE_FREE(ma->texpaintslot);
+ 
+ 	GPU_material_free(&ma->gpumaterial);
  
- 	if (ma->gpumaterial.first)
- 		GPU_material_free(&ma->gpumaterial);
+ 	BKE_previewimg_free(&ma->preview);
+ 	BKE_icon_id_delete((ID *)ma);
  }
  
 -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/world.c
index 13844d6,6395ee6..d07cfdb
--- a/source/blender/blenkernel/intern/world.c
+++ b/source/blender/blenkernel/intern/world.c
@@@ -67,26 -93,23 +93,21 @@@ void BKE_world_free(World *wrld, const 
  
  	/* is no lib link block, but world extension */
  	if (wrld->nodetree) {
- 		ntreeFreeTree_ex(wrld->nodetree, do_id_user);
+ 		ntreeFreeTree(wrld->nodetree, do_id_user);
  		MEM_freeN(wrld->nodetree);
+ 		wrld->nodetree = NULL;
  	}
  
- 	if (wrld->gpumaterial.first)
- 		GPU_material_free(&wrld->gpumaterial);
+ 	GPU_material_free(&wrld->gpumaterial);
  	
+ 	BKE_previewimg_free(&wrld->preview);
  	BKE_icon_id_delete((struct ID *)wrld);
- 	wrld->id.icon_id = 0;
- }
- 
- void BKE_world_free(World *wrld)
- {
- 	BKE_world_free_ex(wrld, true);
  }
  
 -World *add_world(Main *bmain, const char *name)
 +void BKE_world_init(World *wrld)
  {
 -	World *wrld;
 +	BLI_assert(MEMCMP_NULL_STRUCT_OFS(wrld, id));
  
 -	wrld = BKE_libblock_alloc(bmain, ID_WO, name);
 -	
  	wrld->horr =

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list