[Bf-blender-cvs] [aa3d88d] master: Fix T35328: Disk caches of multiple particle systems on a single object overwrite each other

Sergey Sharybin noreply at git.blender.org
Wed Feb 5 18:46:59 CET 2014


Commit: aa3d88d34d3b3a352073e6449b092b6e23033127
Author: Sergey Sharybin
Date:   Wed Feb 5 23:46:10 2014 +0600
https://developer.blender.org/rBaa3d88d34d3b3a352073e6449b092b6e23033127

Fix T35328: Disk caches of multiple particle systems on a single object overwrite each other

It was intended to work actually using particle cache's stack index
but this index might have been calculated incorrect in special case:

* With default cube scene, add particle system to the cube
* Add disk cache to the particle system
* Save file and reload it
* Add another particle system and enable disk cache

This would lead to two point caches with the same stack index of zero.
This happened because point cache indices list wasn't stored in the
.blend file so once you've reload your file blender doesn't know anything
about number or point caches used.

And what was even more confusing is that point cache indices list was
trying to be load from the file, but this failed because it wasn't in the
file.

This commit solves the root of the issue which is ability of producing
.blend file with two point caches using the same disk cache. This is
done by making it sure that point cache indices list is stored in the
.blend file. And also made it so disabling disk cache will tag it to
recalculate stack index.

Old broken files wouldn't magically start working, but fixing them is
rather simple manually by toggling Disk Cache option.

Reviewers: lukastoenne, brecht

CC: sergof

Differential Revision: https://developer.blender.org/D286

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

M	source/blender/blenkernel/BKE_object.h
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenkernel/intern/pointcache.c
M	source/blender/blenloader/intern/writefile.c

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

diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index f9a3f19..72c4c21 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -173,7 +173,7 @@ void BKE_object_sculpt_modifiers_changed(struct Object *ob);
 int BKE_object_obdata_texspace_get(struct Object *ob, short **r_texflag, float **r_loc, float **r_size, float **r_rot);
 
 int BKE_object_insert_ptcache(struct Object *ob);
-// void object_delete_ptcache(struct Object *ob, int index);
+void BKE_object_delete_ptcache(struct Object *ob, int index);
 struct KeyBlock *BKE_object_insert_shape_key(struct Scene *scene, struct Object *ob, const char *name, const bool from_mix);
 
 bool BKE_object_is_child_recursive(struct Object *ob_parent, struct Object *ob_child);
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 3d08ec2..05365a8 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -3188,7 +3188,6 @@ int BKE_object_insert_ptcache(Object *ob)
 	return i;
 }
 
-#if 0
 static int pc_findindex(ListBase *listbase, int index)
 {
 	LinkData *link = NULL;
@@ -3198,7 +3197,7 @@ static int pc_findindex(ListBase *listbase, int index)
 	
 	link = listbase->first;
 	while (link) {
-		if ((int)link->data == index)
+		if (GET_INT_FROM_POINTER(link->data) == index)
 			return number;
 		
 		number++;
@@ -3208,13 +3207,12 @@ static int pc_findindex(ListBase *listbase, int index)
 	return -1;
 }
 
-void object_delete_ptcache(Object *ob, int index) 
+void BKE_object_delete_ptcache(Object *ob, int index)
 {
 	int list_index = pc_findindex(&ob->pc_ids, index);
 	LinkData *link = BLI_findlink(&ob->pc_ids, list_index);
 	BLI_freelinkN(&ob->pc_ids, link);
 }
-#endif
 
 /* shape key utility function */
 
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 7b3539d..271160a 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -3483,6 +3483,13 @@ void BKE_ptcache_toggle_disk_cache(PTCacheID *pid)
 	BKE_ptcache_id_time(pid, NULL, 0.0f, NULL, NULL, NULL);
 
 	BKE_ptcache_update_info(pid);
+
+	if ((cache->flag & PTCACHE_DISK_CACHE) == 0) {
+		if (cache->index) {
+			BKE_object_delete_ptcache(pid->ob, cache->index);
+			cache->index = -1;
+		}
+	}
 }
 
 void BKE_ptcache_disk_cache_rename(PTCacheID *pid, const char *name_src, const char *name_dst)
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 0b582da..129e980 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1542,6 +1542,7 @@ static void write_objects(WriteData *wd, ListBase *idbase)
 			write_particlesystems(wd, &ob->particlesystem);
 			write_modifiers(wd, &ob->modifiers);
 
+			writelist(wd, DATA, "LinkData", &ob->pc_ids);
 			writelist(wd, DATA, "LodLevel", &ob->lodlevels);
 		}
 		ob= ob->id.next;




More information about the Bf-blender-cvs mailing list