[Bf-blender-cvs] [1106645] gooseberry: Fix for indirectly linked object pointers in cache libraries.

Lukas Tönne noreply at git.blender.org
Mon Mar 23 13:01:45 CET 2015


Commit: 1106645500e94455f340ba29c73f33cd8ff43ad7
Author: Lukas Tönne
Date:   Thu Feb 26 17:14:46 2015 +0100
Branches: gooseberry
https://developer.blender.org/rB1106645500e94455f340ba29c73f33cd8ff43ad7

Fix for indirectly linked object pointers in cache libraries.

These must be made "extern" to avoid losing links on loading.

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

M	source/blender/blenkernel/intern/cache_library.c
M	source/blender/blenloader/intern/readfile.c

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

diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 5914a62..b04fd04 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -326,6 +326,17 @@ static bool cache_item_cmp(const void *key_a, const void *key_b)
 	return false;
 }
 
+BLI_INLINE void print_cachelib_items(CacheLibrary *cachelib)
+{
+	CacheItem *item;
+	int i;
+	
+	printf("Cache Library %s:\n", cachelib->id.name+2);
+	for (item = cachelib->items.first, i = 0; item; item = item->next, ++i) {
+		printf("  Item %d: ob=%s, type=%d, index=%d, hash=%d\n", i, item->ob ? item->ob->id.name+2 : "!!!", item->type, item->index, cache_item_hash(item));
+	}
+}
+
 const char *BKE_cache_item_name_prefix(int type)
 {
 	/* note: avoid underscores and the like here,
@@ -411,6 +422,8 @@ CacheItem *BKE_cache_library_add_item(CacheLibrary *cachelib, struct Object *ob,
 		
 		BLI_addtail(&cachelib->items, item);
 		cache_library_insert_item_hash(cachelib, item, false);
+		
+		id_lib_extern((ID *)item->ob);
 	}
 	
 	return item;
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 85537ab..e6c0a32 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -114,6 +114,7 @@
 
 #include "BKE_armature.h"
 #include "BKE_brush.h"
+#include "BKE_cache_library.h"
 #include "BKE_cloth.h"
 #include "BKE_constraint.h"
 #include "BKE_context.h"
@@ -1983,7 +1984,7 @@ static void direct_link_script(FileData *UNUSED(fd), Script *script)
 static void lib_link_cache_library(FileData *fd, Main *main)
 {
 	CacheLibrary *cachelib;
-	CacheItem *item;
+	CacheItem *item, *item_next;
 	
 	for (cachelib = main->cache_library.first; cachelib; cachelib = cachelib->id.next) {
 		if (cachelib->id.flag & LIB_NEED_LINK) {
@@ -1991,8 +1992,13 @@ static void lib_link_cache_library(FileData *fd, Main *main)
 			
 			cachelib->group = newlibadr_us(fd, cachelib->id.lib, cachelib->group);
 			
-			for (item = cachelib->items.first; item; item = item->next) {
+			for (item = cachelib->items.first; item; item = item_next) {
+				item_next = item->next;
+				
 				item->ob = newlibadr(fd, cachelib->id.lib, item->ob);
+				
+				if (!item->ob)
+					BKE_cache_library_remove_item(cachelib, item);
 			}
 		}
 	}




More information about the Bf-blender-cvs mailing list