[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36735] trunk/blender/source/blender: fix [#27405] Append objects with linked materials they dissapears after save

Campbell Barton ideasman42 at gmail.com
Wed May 18 07:21:44 CEST 2011


Revision: 36735
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36735
Author:   campbellbarton
Date:     2011-05-18 05:21:44 +0000 (Wed, 18 May 2011)
Log Message:
-----------
fix [#27405] Append objects with linked materials they dissapears after save
when linking in files to an unsaved blend file, make all library paths absolute.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/intern/bpath.c
    trunk/blender/source/blender/blenloader/intern/readfile.c

Modified: trunk/blender/source/blender/blenlib/intern/bpath.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/bpath.c	2011-05-17 18:37:44 UTC (rev 36734)
+++ trunk/blender/source/blender/blenlib/intern/bpath.c	2011-05-18 05:21:44 UTC (rev 36735)
@@ -750,7 +750,9 @@
 	
 	/* be sure there is low chance of the path being too short */
 	char filepath_absolute[(FILE_MAXDIR * 2) + FILE_MAXFILE];
-	
+
+	BLI_assert(basedir[0] != '\0');
+
 	BLI_bpathIterator_init(&bpi, bmain, basedir, 0);
 	while (!BLI_bpathIterator_isDone(bpi)) {
 		BLI_bpathIterator_getPath(bpi, filepath);

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2011-05-17 18:37:44 UTC (rev 36734)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2011-05-18 05:21:44 UTC (rev 36735)
@@ -5511,22 +5511,33 @@
 	}
 }
 
-/* Always call this once you havbe loaded new library data to set the relative paths correctly in relation to the blend file */
+/* Always call this once you have loaded new library data to set the relative paths correctly in relation to the blend file */
 static void fix_relpaths_library(const char *basepath, Main *main)
 {
 	Library *lib;
 	/* BLO_read_from_memory uses a blank filename */
-	if (basepath==NULL || basepath[0] == '\0')
-		return;
-		
-	for(lib= main->library.first; lib; lib= lib->id.next) {
-		/* Libraries store both relative and abs paths, recreate relative paths,
-		 * relative to the blend file since indirectly linked libs will be relative to their direct linked library */
-		if (strncmp(lib->name, "//", 2)==0) { /* if this is relative to begin with? */
-			strncpy(lib->name, lib->filepath, sizeof(lib->name));
-			BLI_path_rel(lib->name, basepath);
+	if (basepath==NULL || basepath[0] == '\0') {
+		for(lib= main->library.first; lib; lib= lib->id.next) {
+			/* when loading a linked lib into a file which has not been saved,
+			 * there is nothing we can be relative to, so instead we need to make
+			 * it absolute. This can happen when appending an object with a relative
+			 * link into an unsaved blend file. See [#27405].
+			 * The remap relative option will make it relative again on save - campbell */
+			if (strncmp(lib->name, "//", 2)==0) {
+				strncpy(lib->name, lib->filepath, sizeof(lib->name));
+			}
 		}
 	}
+	else {
+		for(lib= main->library.first; lib; lib= lib->id.next) {
+			/* Libraries store both relative and abs paths, recreate relative paths,
+			 * relative to the blend file since indirectly linked libs will be relative to their direct linked library */
+			if (strncmp(lib->name, "//", 2)==0) { /* if this is relative to begin with? */
+				strncpy(lib->name, lib->filepath, sizeof(lib->name));
+				BLI_path_rel(lib->name, basepath);
+			}
+		}
+	}
 }
 
 /* ************** READ SOUND ******************* */




More information about the Bf-blender-cvs mailing list