diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-05-18 09:21:44 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-05-18 09:21:44 +0400 |
commit | edb9045824064267e6efe27f58069b69bfc833f8 (patch) | |
tree | ce977ac36eae1426dccb8a04ee4af93fda90c682 /source | |
parent | dc500038248e3edc47347c6de4fd7d0312ace54f (diff) |
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.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/intern/bpath.c | 4 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 31 |
2 files changed, 24 insertions, 11 deletions
diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index a56b1392b69..640091b1ab3 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -750,7 +750,9 @@ void makeFilesAbsolute(Main *bmain, const char *basedir, ReportList *reports) /* 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); diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index d6d9a4c88c9..e669be2281d 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -5511,20 +5511,31 @@ static void lib_link_library(FileData *UNUSED(fd), Main *main) } } -/* 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); + } } } } |