[Bf-blender-cvs] [c6d3f76] asset-engine: Fix save/load issues with new virtual-lib assets.

Bastien Montagne noreply at git.blender.org
Tue Jun 14 15:49:07 CEST 2016


Commit: c6d3f76e69fbd213e6076071da67dd700e522c4f
Author: Bastien Montagne
Date:   Tue Jun 14 15:47:54 2016 +0200
Branches: asset-engine
https://developer.blender.org/rBc6d3f76e69fbd213e6076071da67dd700e522c4f

Fix save/load issues with new virtual-lib assets.

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

M	source/blender/blenkernel/intern/library.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c

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

diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index d3c5afe..f35dd97 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -2046,10 +2046,11 @@ static void library_asset_dependencies_rebuild(ID *asset)
 	BLI_assert(lib && lib->asset_repository);
 
 	if (!(lib && lib->asset_repository)) {
+		printf("asset: %s\n", asset->name);
 		printf("lib: %p\n", lib);
 		printf("lib: %s\n", lib->id.name);
 		printf("lib: %s\n", lib->name);
-		printf("lib: %p\n", lib->asset_repository);
+		printf("lib: %p\n\n\n", lib->asset_repository);
 	}
 
 	asset->tag |= LIB_TAG_ASSET;
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 1c045d9..3950076 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2148,6 +2148,9 @@ static void direct_link_id(FileData *fd, ID *id)
 		/* this case means the data was written incorrectly, it should not happen */
 		IDP_DirectLinkGroup_OrFree(&id->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
 	}
+	if (id->uuid) {
+		id->uuid = newdataadr(fd, id->uuid);
+	}
 }
 
 /* ************ READ CurveMapping *************** */
@@ -8019,6 +8022,7 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short
 		return blo_nextbhead(fd, bhead);
 	
 	id->tag = tag | LIB_TAG_NEED_LINK;
+	printf("id: %s (%p, %p), lib: %p\n", id->name, id, id->uuid, main->curlib);
 	id->lib = main->curlib;
 	id->us = ID_FAKE_USERS(id);
 	id->icon_id = 0;
@@ -8491,7 +8495,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
 			bhead->code = ID_SCR;
 			/* deliberate pass on to default */
 		default:
-			bhead = read_libblock(fd, bfd->main, bhead, LIB_TAG_LOCAL, NULL);
+			bhead = read_libblock(fd, mainlist.last, bhead, LIB_TAG_LOCAL, NULL);
 		}
 	}
 	
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 97f6d3c..6d0b6cc 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -294,7 +294,7 @@ typedef struct {
 
 	unsigned char *buf;
 	MemFile *compare, *current;
-	
+
 	int tot, count, error;
 
 	/* Wrap writing, so we can use zlib or
@@ -358,7 +358,7 @@ static void writedata_free(WriteData *wd)
  * \param len Length of new chunk of data
  * \warning Talks to other functions with global parameters
  */
- 
+
 #define MYWRITE_FLUSH		NULL
 
 static void mywrite(WriteData *wd, const void *adr, int len)
@@ -375,7 +375,7 @@ static void mywrite(WriteData *wd, const void *adr, int len)
 	}
 
 	wd->tot+= len;
-	
+
 	/* if we have a single big chunk, write existing data in
 	 * buffer and write out big chunk in smaller pieces */
 	if (len>MYWRITE_MAX_CHUNK) {
@@ -422,7 +422,7 @@ static WriteData *bgnwrite(WriteWrap *ww, MemFile *compare, MemFile *current)
 	wd->current= current;
 	/* this inits comparing */
 	memfile_chunk_add(compare, NULL, NULL, 0);
-	
+
 	return wd;
 }
 
@@ -440,7 +440,7 @@ static int endwrite(WriteData *wd)
 		writedata_do_write(wd, wd->buf, wd->count);
 		wd->count= 0;
 	}
-	
+
 	err= wd->error;
 	writedata_free(wd);
 
@@ -506,7 +506,7 @@ static void writedata(WriteData *wd, int filecode, int len, const void *adr)  /*
 static void writelist(WriteData *wd, int filecode, const char *structname, ListBase *lb)
 {
 	Link *link = lb->first;
-	
+
 	while (link) {
 		writestruct(wd, filecode, structname, 1, link);
 		link = link->next;
@@ -592,7 +592,14 @@ static void write_iddata(void *wd, ID *id)
 {
 	/* ID_WM's id->properties are considered runtime only, and never written in .blend file. */
 	if (id->properties && !ELEM(GS(id->name), ID_WM)) {
-		IDP_WriteProperty(id->properties, wd);
+		/* We want to write IDProps from 'virtual' libraries too, but not from 'real' linked datablocks... */
+		if (!id->uuid || (id->lib && (id->lib->flag & LIBRARY_FLAG_VIRTUAL))) {
+			IDP_WriteProperty(id->properties, wd);
+		}
+	}
+	if (id->uuid) {
+		BLI_assert(id->lib && id->lib->asset_repository);
+		writestruct(wd, DATA, "AssetUUID", 1, id->uuid);
 	}
 }
 
@@ -626,25 +633,25 @@ static void write_previews(WriteData *wd, PreviewImage *prv)
 static void write_fmodifiers(WriteData *wd, ListBase *fmodifiers)
 {
 	FModifier *fcm;
-	
+
 	/* Write all modifiers first (for faster reloading) */
 	writelist(wd, DATA, "FModifier", fmodifiers);
-	
+
 	/* Modifiers */
 	for (fcm= fmodifiers->first; fcm; fcm= fcm->next) {
 		const FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm);
-		
+
 		/* Write the specific data */
 		if (fmi && fcm->data) {
 			/* firstly, just write the plain fmi->data struct */
 			writestruct(wd, DATA, fmi->structName, 1, fcm->data);
-			
+
 			/* do any modifier specific stuff */
 			switch (fcm->type) {
 				case FMODIFIER_TYPE_GENERATOR:
 				{
 					FMod_Generator *data= (FMod_Generator *)fcm->data;
-					
+
 					/* write coefficients array */
 					if (data->coefficients)
 						writedata(wd, DATA, sizeof(float)*(data->arraysize), data->coefficients);
@@ -654,7 +661,7 @@ static void write_fmodifiers(WriteData *wd, ListBase *fmodifiers)
 				case FMODIFIER_TYPE_ENVELOPE:
 				{
 					FMod_Envelope *data= (FMod_Envelope *)fcm->data;
-					
+
 					/* write envelope data */
 					if (data->data)
 						writestruct(wd, DATA, "FCM_EnvelopeData", data->totvert, data->data);
@@ -664,7 +671,7 @@ static void write_fmodifiers(WriteData *wd, ListBase *fmodifiers)
 				case FMODIFIER_TYPE_PYTHON:
 				{
 					FMod_Python *data = (FMod_Python *)fcm->data;
-					
+
 					/* Write ID Properties -- and copy this comment EXACTLY for easy finding
 					 * of library blocks that implement this.*/
 					IDP_WriteProperty(data->prop, wd);
@@ -679,7 +686,7 @@ static void write_fmodifiers(WriteData *wd, ListBase *fmodifiers)
 static void write_fcurves(WriteData *wd, ListBase *fcurves)
 {
 	FCurve *fcu;
-	
+
 	writelist(wd, DATA, "FCurve", fcurves);
 	for (fcu=fcurves->first; fcu; fcu=fcu->next) {
 		/* curve data */
@@ -687,20 +694,20 @@ static void write_fcurves(WriteData *wd, ListBase *fcurves)
 			writestruct(wd, DATA, "BezTriple", fcu->totvert, fcu->bezt);
 		if (fcu->fpt)
 			writestruct(wd, DATA, "FPoint", fcu->totvert, fcu->fpt);
-			
+
 		if (fcu->rna_path)
 			writedata(wd, DATA, strlen(fcu->rna_path)+1, fcu->rna_path);
-		
+
 		/* driver data */
 		if (fcu->driver) {
 			ChannelDriver *driver= fcu->driver;
 			DriverVar *dvar;
-			
+
 			writestruct(wd, DATA, "ChannelDriver", 1, driver);
-			
+
 			/* variables */
 			writelist(wd, DATA, "DriverVar", &driver->variables);
-			for (dvar= driver->variables.first; dvar; dvar= dvar->next) {				
+			for (dvar= driver->variables.first; dvar; dvar= dvar->next) {
 				DRIVER_TARGETS_USED_LOOPER(dvar)
 				{
 					if (dtar->rna_path)
@@ -709,7 +716,7 @@ static void write_fcurves(WriteData *wd, ListBase *fcurves)
 				DRIVER_TARGETS_LOOPER_END
 			}
 		}
-		
+
 		/* write F-Modifiers */
 		write_fmodifiers(wd, &fcu->modifiers);
 	}
@@ -720,24 +727,24 @@ static void write_actions(WriteData *wd, ListBase *idbase)
 	bAction	*act;
 	bActionGroup *grp;
 	TimeMarker *marker;
-	
+
 	for (act=idbase->first; act; act= act->id.next) {
 		if (act->id.us>0 || wd->current) {
 			writestruct(wd, ID_AC, "bAction", 1, act);
 			write_iddata(wd, &act->id);
 
 			write_fcurves(wd, &act->curves);
-			
+
 			for (grp=act->groups.first; grp; grp=grp->next) {
 				writestruct(wd, DATA, "bActionGroup", 1, grp);
 			}
-			
+
 			for (marker=act->markers.first; marker; marker=marker->next) {
 				writestruct(wd, DATA, "TimeMarker", 1, marker);
 			}
 		}
 	}
-	
+
 	/* flush helps the compression for undo-save */
 	mywrite(wd, MYWRITE_FLUSH, 0);
 }
@@ -746,16 +753,16 @@ static void write_keyingsets(WriteData *wd, ListBase *list)
 {
 	KeyingSet *ks;
 	KS_Path *ksp;
-	
+
 	for (ks= list->first; ks; ks= ks->next) {
 		/* KeyingSet */
 		writestruct(wd, DATA, "KeyingSet", 1, ks);
-		
+
 		/* Paths */
 		for (ksp= ks->paths.first; ksp; ksp= ksp->next) {
 			/* Path */
 			writestruct(wd, DATA, "KS_Path", 1, ksp);
-			
+
 			if (ksp->rna_path)
 				writedata(wd, DATA, strlen(ksp->rna_path)+1, ksp->rna_path);
 		}
@@ -765,13 +772,13 @@ static void write_keyingsets(WriteData *wd, ListBase *list)
 static void write_nlastrips(WriteData *wd, ListBase *strips)
 {
 	NlaStrip *strip;
-	
+
 	writelist(wd, DATA, "NlaStrip", strips);
 	for (strip= strips->first; strip; strip= strip->next) {
 		/* write the strip's F-Curves and modifiers */
 		write_fcurves(wd, &strip->fcurves);
 		write_fmodifiers(wd, &strip->modifiers);
-		
+
 		/* write the strip's children */
 		write_nlastrips(wd, &strip->strips);
 	}
@@ -780,12 +787,12 @@ static void write_nlastrips(WriteData *wd, ListBase *strips)
 static void write_nladata(WriteData *wd, ListBase *nlabase)
 {
 	NlaTrack *nlt;
-	
+
 	/* write all the tracks */
 	for (nlt= nlabase->first; nlt; nlt= nlt->next) {
 		/* write the track first */
 		writestruct(wd, DATA, "NlaTrack", 1, nlt);
-		
+
 		/* write the track's strips */
 		write_nlastrips(wd, &nlt->strips);
 	}
@@ -794,13 +801,13 @@ static void write_nladata(WriteData *wd, ListBase *nlabase)
 static void write_animdata(WriteData *wd, AnimData *adt)
 {
 	AnimOverride *aor;
-	
+
 	/* firstly, just write the AnimData block */
 	writestruct(wd, DATA, "AnimData", 1, adt);
-	
+
 	/* write drivers */
 	write_fcurves(wd, &adt->drivers);
-	
+
 	/* write overrides */
 	// FIXME: are these needed?
 	for (aor= adt->overrides.first; aor; aor= aor->next) {
@@ -808,9 +815,9 @@ static void write_animdata(WriteData *wd, AnimData *adt)
 		writestruct(wd, DATA, "AnimOverride", 1, aor);
 		writedata(wd, DATA, strlen(aor->rna_path)+1, aor->rna_path);
 	}
-	
+
 	// TODO write the remaps (if they are needed)
-	
+
 	/* write NLA data */
 	write_nladata(wd, &adt->nla_tracks);
 }
@@ -835,14 +842,14 @@ static void write_node_socket(WriteData *wd, bNodeTree *UNUSED(ntree), bNode *no
 #ifdef USE_NODE_COMPAT_CUSTOMNODES
 	/* forward compatibility code, so older blenders still open */
 	sock->stack_type = 1;
-	
+
 	if (node->type == NODE_GROUP) {
 		bNodeTree *ngroup = (bNodeTree *)node->id;
 		if (ngroup) {
 			/* for node gro

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list