[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24010] trunk/blender/source/blender/ blenloader/intern: Bugfixes for quit.blend + library linking, the last commit didn't solve

Brecht Van Lommel brecht at blender.org
Tue Oct 20 18:43:25 CEST 2009


Revision: 24010
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24010
Author:   blendix
Date:     2009-10-20 18:43:25 +0200 (Tue, 20 Oct 2009)

Log Message:
-----------
Bugfixes for quit.blend + library linking, the last commit didn't solve
that completely:

* quit.blend is saved from the undo file, which did not save out library
  ID_LI and ID_ID blocks, for quick undo keeping the library datablocks.
  However this means library links are lost on reading the quit.blend, so
  now instead of not writing them, they are not read on undo.
* Libraries were not not using the right path yet always.

Note the screen setup is still not recovered from the quit.blend if no
auto save happened yet, but that is not important enough to spend time on
now.

Modified Paths:
--------------
    trunk/blender/source/blender/blenloader/intern/readblenentry.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/blenloader/intern/readfile.h
    trunk/blender/source/blender/blenloader/intern/writefile.c

Modified: trunk/blender/source/blender/blenloader/intern/readblenentry.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readblenentry.c	2009-10-20 16:31:03 UTC (rev 24009)
+++ trunk/blender/source/blender/blenloader/intern/readblenentry.c	2009-10-20 16:43:25 UTC (rev 24010)
@@ -364,7 +364,7 @@
 	fd = blo_openblendermemfile(memfile, reports);
 	if (fd) {
 		fd->reports= reports;
-		strcpy(fd->filename, filename);
+		strcpy(fd->relabase, filename);
 		
 		/* clear ob->proxy_from pointers in old main */
 		blo_clear_proxy_pointers_from_lib(fd, oldmain);

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2009-10-20 16:31:03 UTC (rev 24009)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2009-10-20 16:43:25 UTC (rev 24010)
@@ -977,7 +977,7 @@
 		fd->read = fd_read_gzip_from_file;
 
 		/* needed for library_append and read_libraries */
-		BLI_strncpy(fd->filename, name, sizeof(fd->filename));
+		BLI_strncpy(fd->relabase, name, sizeof(fd->relabase));
 
 		return blo_decode_and_check(fd, reports);
 	}
@@ -5134,7 +5134,7 @@
 	}
 	/* make sure we have full path in lib->filename */
 	BLI_strncpy(lib->filename, lib->name, sizeof(lib->name));
-	cleanup_path(fd->filename, lib->filename);
+	cleanup_path(fd->relabase, lib->filename);
 	
 //	printf("direct_link_library: name %s\n", lib->name);
 //	printf("direct_link_library: filename %s\n", lib->filename);
@@ -5469,6 +5469,8 @@
 	bfd->displaymode= fg->displaymode;
 	bfd->globalf= fg->globalf;
 	BLI_strncpy(bfd->filename, fg->filename, sizeof(bfd->filename));
+	if(G.fileflags & G_FILE_RECOVER)
+		BLI_strncpy(fd->relabase, fg->filename, sizeof(fd->relabase));
 	
 	bfd->curscreen= fg->curscreen;
 	bfd->curscene= fg->curscene;
@@ -6284,7 +6286,7 @@
 	/* WATCH IT!!!: pointers from libdata have not been converted */
 
 	if(G.f & G_DEBUG)
-		printf("read file %s\n  Version %d sub %d\n", fd->filename, main->versionfile, main->subversionfile);
+		printf("read file %s\n  Version %d sub %d\n", fd->relabase, main->versionfile, main->subversionfile);
 	
 	if(main->versionfile == 100) {
 		/* tex->extend and tex->imageflag have changed: */
@@ -10058,14 +10060,25 @@
 			break;
 
 		case ID_LI:
-			bhead = read_libblock(fd, bfd->main, bhead, LIB_LOCAL, NULL);
+			/* skip library datablocks in undo, this works together with
+			   BLO_read_from_memfile, where the old main->library is restored
+			   overwriting  the libraries from the memory file. previously
+			   it did not save ID_LI/ID_ID blocks in this case, but they are
+			   needed to make quit.blend recover them correctly. */
+			if(fd->memfile)
+				bhead= blo_nextbhead(fd, bhead);
+			else
+				bhead= read_libblock(fd, bfd->main, bhead, LIB_LOCAL, NULL);
 			break;
 		case ID_ID:
+			/* same as above */
+			if(fd->memfile)
+				bhead= blo_nextbhead(fd, bhead);
+			else
 				/* always adds to the most recently loaded
 				 * ID_LI block, see direct_link_library.
-				 * this is part of the file format definition.
-				 */
-			bhead = read_libblock(fd, fd->mainlist.last, bhead, LIB_READ+LIB_EXTERN, NULL);
+				 * this is part of the file format definition. */
+				bhead = read_libblock(fd, fd->mainlist.last, bhead, LIB_READ+LIB_EXTERN, NULL);
 			break;
 			
 			/* in 2.50+ files, the file identifier for screens is patched, forward compatibility */
@@ -10087,7 +10100,7 @@
 
 	lib_link_all(fd, bfd->main);
 	lib_verify_nodetree(bfd->main, 1);
-	fix_relpaths_library(fd->filename, bfd->main); /* make all relative paths, relative to the open blend file */
+	fix_relpaths_library(fd->relabase, bfd->main); /* make all relative paths, relative to the open blend file */
 	
 	link_global(fd, bfd);	/* as last */
 	
@@ -10135,6 +10148,10 @@
 
 static BHead *find_previous_lib(FileData *fd, BHead *bhead)
 {
+	/* skip library datablocks in undo, see comment in read_libblock */
+	if(fd->memfile)
+		return NULL;
+
 	for (; bhead; bhead= blo_prevbhead(fd, bhead))
 		if (bhead->code==ID_LI)
 			break;
@@ -10206,7 +10223,7 @@
 
 			if(bheadlib) {
 				Library *lib= read_struct(fd, bheadlib, "Library");
-				Main *ptr= blo_find_main(fd, &fd->mainlist, lib->name, fd->filename);
+				Main *ptr= blo_find_main(fd, &fd->mainlist, lib->name, fd->relabase);
 
 				id= is_yet_read(fd, ptr, bhead);
 
@@ -11464,7 +11481,7 @@
 	fd->read = fd_read_from_file;
 
 	/* needed for library_append and read_libraries */
-	BLI_strncpy(fd->filename, name, sizeof(fd->filename));
+	BLI_strncpy(fd->relabase, name, sizeof(fd->relabase));
 
 	fd = blo_decode_and_check(fd, reports);
 	if (!fd)

Modified: trunk/blender/source/blender/blenloader/intern/readfile.h
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.h	2009-10-20 16:31:03 UTC (rev 24009)
+++ trunk/blender/source/blender/blenloader/intern/readfile.h	2009-10-20 16:43:25 UTC (rev 24010)
@@ -56,7 +56,7 @@
 	gzFile gzfiledes;
 
 	// now only in use for library appending
-	char filename[FILE_MAXDIR+FILE_MAXFILE];
+	char relabase[FILE_MAXDIR+FILE_MAXFILE];
 	
 	// variables needed for reading from stream
 	char headerdone;

Modified: trunk/blender/source/blender/blenloader/intern/writefile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/writefile.c	2009-10-20 16:31:03 UTC (rev 24009)
+++ trunk/blender/source/blender/blenloader/intern/writefile.c	2009-10-20 16:43:25 UTC (rev 24010)
@@ -2383,8 +2383,7 @@
 	write_brushes  (wd, &mainvar->brush);
 	write_scripts  (wd, &mainvar->script);
 	write_gpencils (wd, &mainvar->gpencil);
-	if(current==NULL)	
-		write_libraries(wd,  mainvar->next); /* no library save in undo */
+	write_libraries(wd,  mainvar->next);
 
 	if (write_user_block) {
 		write_userdef(wd);





More information about the Bf-blender-cvs mailing list