[Bf-blender-cvs] [1a17fcf] alembic_basic_io: Properly ref-count CacheFile block usage, add a function to copy the block.

Kévin Dietrich noreply at git.blender.org
Fri Jun 24 22:29:34 CEST 2016


Commit: 1a17fcf3b3d1523df80eeb0b372f5890f1b9db37
Author: Kévin Dietrich
Date:   Fri Jun 24 22:15:32 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rB1a17fcf3b3d1523df80eeb0b372f5890f1b9db37

Properly ref-count CacheFile block usage, add a function to copy the
block.

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

M	source/blender/alembic/intern/abc_object.cc
M	source/blender/alembic/intern/alembic_capi.cc
M	source/blender/blenkernel/BKE_cachefile.h
M	source/blender/blenkernel/intern/cachefile.c
M	source/blender/blenkernel/intern/constraint.c
M	source/blender/blenkernel/intern/library.c
M	source/blender/modifiers/intern/MOD_meshsequencecache.c

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

diff --git a/source/blender/alembic/intern/abc_object.cc b/source/blender/alembic/intern/abc_object.cc
index 1eabf91..ac80e08 100644
--- a/source/blender/alembic/intern/abc_object.cc
+++ b/source/blender/alembic/intern/abc_object.cc
@@ -25,6 +25,7 @@
 #include "abc_util.h"
 
 extern "C" {
+#include "DNA_cachefile_types.h"
 #include "DNA_constraint_types.h"
 #include "DNA_modifier_types.h"
 #include "DNA_object_types.h"
@@ -33,6 +34,7 @@ extern "C" {
 #include "BKE_constraint.h"
 #include "BKE_depsgraph.h"
 #include "BKE_idprop.h"
+#include "BKE_library.h"
 #include "BKE_modifier.h"
 #include "BKE_object.h"
 
@@ -178,8 +180,10 @@ void AbcObjectReader::readObjectMatrix(const float time)
 	if (!schema.isConstant()) {
 		bConstraint *con = BKE_constraint_add_for_object(m_object, NULL, CONSTRAINT_TYPE_TRANSFORMCACHE);
 		bTransformCacheConstraint *data = static_cast<bTransformCacheConstraint *>(con->data);
-		data->cache_file = m_settings->cache_file;
 		BLI_strncpy(data->abc_object_path, m_iobject.getFullName().c_str(), FILE_MAX);
+
+		data->cache_file = m_settings->cache_file;
+		id_us_plus(&data->cache_file->id);
 	}
 }
 
@@ -191,6 +195,8 @@ void AbcObjectReader::addDefaultModifier(Main *bmain) const
 	MeshSeqCacheModifierData *mcmd = reinterpret_cast<MeshSeqCacheModifierData *>(md);
 
 	mcmd->cache_file = m_settings->cache_file;
+	id_us_plus(&mcmd->cache_file->id);
+
 	BLI_strncpy(mcmd->abc_object_path, m_iobject.getFullName().c_str(), FILE_MAX);
 
 	DAG_id_tag_update(&m_object->id, OB_RECALC_DATA);
diff --git a/source/blender/alembic/intern/alembic_capi.cc b/source/blender/alembic/intern/alembic_capi.cc
index dfb98e5..37158e0 100644
--- a/source/blender/alembic/intern/alembic_capi.cc
+++ b/source/blender/alembic/intern/alembic_capi.cc
@@ -539,6 +539,11 @@ static void import_startjob(void *user_data, short *stop, short *do_update, floa
 
 	CacheFile *cache_file = static_cast<CacheFile *>(BKE_cachefile_add(data->bmain, BLI_path_basename(data->filename)));
 
+	/* Decrement the ID ref-count because it is going to be incremented for each
+	 * modifier and constraint that it will be attached to, so since currently
+	 * it is not used by anyone, its use count will off by one. */
+	id_us_min(&cache_file->id);
+
 	cache_file->is_sequence = data->settings.is_sequence;
 	cache_file->scale = data->settings.scale;
 	cache_file->handle = handle_from_archive(archive);
diff --git a/source/blender/blenkernel/BKE_cachefile.h b/source/blender/blenkernel/BKE_cachefile.h
index f81c5aa..487c6d9 100644
--- a/source/blender/blenkernel/BKE_cachefile.h
+++ b/source/blender/blenkernel/BKE_cachefile.h
@@ -41,6 +41,8 @@ void *BKE_cachefile_add(struct Main *bmain, const char *name);
 
 void BKE_cachefile_free(struct CacheFile *cache_file);
 
+struct CacheFile *BKE_cachefile_copy(struct Main *bmain, struct CacheFile *cache_file);
+
 void BKE_cachefile_load(struct CacheFile *cache_file, const char *relabase);
 
 void BKE_cachefile_update_frame(struct Main *bmain, float ctime);
diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c
index b4d8619..adf3837 100644
--- a/source/blender/blenkernel/intern/cachefile.c
+++ b/source/blender/blenkernel/intern/cachefile.c
@@ -64,6 +64,7 @@ void *BKE_cachefile_add(Main *bmain, const char *name)
 	cache_file->frame_start = 0.0f;
 	cache_file->frame_scale = 1.0f;
 	cache_file->is_sequence = false;
+	cache_file->scale = 1.0f;
 
 	return cache_file;
 }
@@ -78,6 +79,28 @@ void BKE_cachefile_free(CacheFile *cache_file)
 #endif
 }
 
+CacheFile *BKE_cachefile_copy(Main *bmain, CacheFile *cache_file)
+{
+	CacheFile *new_cache_file = BKE_cachefile_add(bmain, cache_file->id.name + 2);
+
+	BLI_strncpy(new_cache_file->filepath, cache_file->filepath, FILE_MAX);
+
+	new_cache_file->frame_start = cache_file->frame_start;
+	new_cache_file->frame_scale = cache_file->frame_scale;
+	new_cache_file->is_sequence = cache_file->is_sequence;
+	new_cache_file->scale = cache_file->scale;
+
+	if (cache_file->handle) {
+		BKE_cachefile_load(new_cache_file, bmain->name);
+	}
+
+	if (cache_file->id.lib) {
+		BKE_id_lib_local_paths(G.main, cache_file->id.lib, &new_cache_file->id);
+	}
+
+	return new_cache_file;
+}
+
 void BKE_cachefile_load(CacheFile *cache_file, const char *relabase)
 {
 	char filename[FILE_MAX];
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 4fd24aa..51856f4 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -4361,14 +4361,36 @@ static void transformcache_evaluate(bConstraint *con, bConstraintOb *cob, ListBa
 	UNUSED_VARS(targets);
 }
 
+static void transformcache_copy(bConstraint *con, bConstraint *srccon)
+{
+	bTransformCacheConstraint *src = srccon->data;
+	bTransformCacheConstraint *dst = con->data;
+
+	BLI_strncpy(dst->abc_object_path, src->abc_object_path, sizeof(dst->abc_object_path));
+	dst->cache_file = src->cache_file;
+
+	if (dst->cache_file) {
+		id_us_plus(&dst->cache_file->id);
+	}
+}
+
+static void transformcache_free(bConstraint *con)
+{
+	bTransformCacheConstraint *data = con->data;
+
+	if (data->cache_file) {
+		id_us_min(&data->cache_file->id);
+	}
+}
+
 static bConstraintTypeInfo CTI_TRANSFORMCACHE = {
 	CONSTRAINT_TYPE_TRANSFORMCACHE, /* type */
 	sizeof(bTransformCacheConstraint), /* size */
 	"Transform Cache", /* name */
 	"bTransformCacheConstraint", /* struct name */
-	NULL,  /* free data */
+	transformcache_free,  /* free data */
 	transformcache_id_looper,  /* id looper */
-	NULL,  /* copy data */
+	transformcache_copy,  /* copy data */
 	NULL,  /* new data */
 	NULL,  /* get constraint targets */
 	NULL,  /* flush constraint targets */
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 5942484..fca9094 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -83,6 +83,7 @@
 #include "BKE_bpath.h"
 #include "BKE_brush.h"
 #include "BKE_camera.h"
+#include "BKE_cachefile.h"
 #include "BKE_context.h"
 #include "BKE_curve.h"
 #include "BKE_depsgraph.h"
@@ -449,7 +450,8 @@ bool id_copy(ID *id, ID **newid, bool test)
 			if (!test) *newid = (ID *)BKE_linestyle_copy(G.main, (FreestyleLineStyle *)id);
 			return true;
 		case ID_CF:
-			return false;  /* not implemented */
+			if (!test) *newid = (ID *)BKE_cachefile_copy(G.main, (CacheFile *)id);
+			return true;  /* not implemented */
 	}
 	
 	return false;
diff --git a/source/blender/modifiers/intern/MOD_meshsequencecache.c b/source/blender/modifiers/intern/MOD_meshsequencecache.c
index 461adf1..e2d40c4 100644
--- a/source/blender/modifiers/intern/MOD_meshsequencecache.c
+++ b/source/blender/modifiers/intern/MOD_meshsequencecache.c
@@ -31,6 +31,7 @@
 
 #include "BKE_cachefile.h"
 #include "BKE_DerivedMesh.h"
+#include "BKE_library.h"
 #include "BKE_library_query.h"
 #include "BKE_scene.h"
 
@@ -52,9 +53,23 @@ static void copyData(ModifierData *md, ModifierData *target)
 {
 #if 0
 	MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md;
-	MeshSeqCacheModifierData *tmcmd = (MeshSeqCacheModifierData *)target;
 #endif
+	MeshSeqCacheModifierData *tmcmd = (MeshSeqCacheModifierData *)target;
+
 	modifier_copyData_generic(md, target);
+
+	if (tmcmd->cache_file) {
+		id_us_plus(&tmcmd->cache_file->id);
+	}
+}
+
+static void freeData(ModifierData *md)
+{
+	MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *) md;
+
+	if (mcmd->cache_file) {
+		id_us_min(&mcmd->cache_file->id);
+	}
 }
 
 static bool isDisabled(ModifierData *md, int UNUSED(useRenderParams))
@@ -119,7 +134,7 @@ ModifierTypeInfo modifierType_MeshSequenceCache = {
     /* applyModifierEM */   NULL,
     /* initData */          initData,
     /* requiredDataMask */  NULL,
-    /* freeData */          NULL,
+    /* freeData */          freeData,
     /* isDisabled */        isDisabled,
     /* updateDepgraph */    NULL,
     /* updateDepsgraph */   NULL,




More information about the Bf-blender-cvs mailing list