diff options
Diffstat (limited to 'source/blender/blenloader')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 61 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 179 |
2 files changed, 121 insertions, 119 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 2be1b958982..082702f6d9d 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -1020,7 +1020,7 @@ static int fd_read_gzip_from_memory(FileData *filedata, void *buffer, unsigned i if (err == Z_STREAM_END) { return 0; } - else if (err != Z_OK) { + else if (err != Z_OK) { printf("fd_read_gzip_from_memory: zlib error\n"); return 0; } @@ -2459,9 +2459,13 @@ static void lib_verify_nodetree(Main *main, int UNUSED(open)) * * XXX this should actually be part of do_versions, * but needs valid typeinfo pointers to create interface nodes. + * + * Note: theoretically only needed in node groups (main->nodetree), + * but due to a temporary bug such links could have been added in all trees, + * so have to clean up all of them ... */ - for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next) { + FOREACH_NODETREE(main, ntree, id) { if (ntree->flag & NTREE_DO_VERSIONS_CUSTOMNODES_GROUP) { bNode *input_node = NULL, *output_node = NULL; int num_inputs = 0, num_outputs = 0; @@ -2541,6 +2545,7 @@ static void lib_verify_nodetree(Main *main, int UNUSED(open)) ntree->flag &= ~(NTREE_DO_VERSIONS_CUSTOMNODES_GROUP | NTREE_DO_VERSIONS_CUSTOMNODES_GROUP_CREATE_INTERFACE); } } + FOREACH_NODETREE_END } /* verify all group user nodes */ @@ -6593,6 +6598,8 @@ static void direct_link_movieclip(FileData *fd, MovieClip *clip) clip->tracking.dopesheet.channels.first = clip->tracking.dopesheet.channels.last = NULL; clip->tracking.dopesheet.coverage_segments.first = clip->tracking.dopesheet.coverage_segments.last = NULL; + clip->prefetch_ok = FALSE; + link_list(fd, &tracking->objects); for (object = tracking->objects.first; object; object = object->next) { @@ -7742,10 +7749,21 @@ static void do_versions_userdef(FileData *fd, BlendFileData *bfd) if (user == NULL) return; + if (MAIN_VERSION_OLDER(bmain, 266, 4)) { + bTheme *btheme; + + /* themes for Node and Sequence editor were not using grid color, but back. we copy this over then */ + for (btheme = user->themes.first; btheme; btheme = btheme->next) { + copy_v4_v4_char(btheme->tnode.grid, btheme->tnode.back); + copy_v4_v4_char(btheme->tseq.grid, btheme->tseq.back); + } + } + if (bmain->versionfile < 267) { if (!DNA_struct_elem_find(fd->filesdna, "UserDef", "short", "image_gpubuffer_limit")) - user->image_gpubuffer_limit = 10; + user->image_gpubuffer_limit = 20; + } } static void do_versions(FileData *fd, Library *lib, Main *main) @@ -9158,13 +9176,13 @@ static void do_versions(FileData *fd, Library *lib, Main *main) } FOREACH_NODETREE_END } - if (!MAIN_VERSION_ATLEAST(main, 266, 2)) { + if (MAIN_VERSION_OLDER(main, 266, 2)) { FOREACH_NODETREE(main, ntree, id) { do_versions_nodetree_customnodes(ntree, ((ID *)ntree == id)); } FOREACH_NODETREE_END } - if (!MAIN_VERSION_ATLEAST(main, 266, 2)) { + if (MAIN_VERSION_OLDER(main, 266, 2)) { bScreen *sc; for (sc= main->screen.first; sc; sc= sc->id.next) { ScrArea *sa; @@ -9200,8 +9218,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) /* Set flag for delayed do_versions in lib_verify_nodetree. It needs valid typeinfo pointers ... */ { - bNodeTree *ntree; - for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next) { + FOREACH_NODETREE(main, ntree, id) { /* XXX This should be kept without version check for now! * As long as USE_NODE_COMPAT_CUSTOMNODES is active, files will write links * to tree interface sockets for forward compatibility. These links need to be removed again @@ -9213,9 +9230,30 @@ static void do_versions(FileData *fd, Library *lib, Main *main) /* Only add interface nodes once. * In old Blender versions they will be removed automatically due to undefined type */ - if (!MAIN_VERSION_ATLEAST(main, 266, 2)) + if (MAIN_VERSION_OLDER(main, 266, 2)) ntree->flag |= NTREE_DO_VERSIONS_CUSTOMNODES_GROUP_CREATE_INTERFACE; } + FOREACH_NODETREE_END + } + + if (MAIN_VERSION_OLDER(main, 266, 3)) { + { + /* Fix for a very old issue: + * Node names were nominally made unique in r24478 (2.50.8), but the do_versions check + * to update existing node names only applied to main->nodetree (i.e. group nodes). + * Uniqueness is now required for proper preview mapping, + * so do this now to ensure old files don't break. + */ + bNode *node; + FOREACH_NODETREE(main, ntree, id) { + if (id == &ntree->id) + continue; /* already fixed for node groups */ + + for (node = ntree->nodes.first; node; node = node->next) + nodeUniqueName(ntree, node); + } + FOREACH_NODETREE_END + } } if (main->versionfile < 267) { @@ -10582,7 +10620,7 @@ static int object_in_any_scene(Main *mainvar, Object *ob) return 0; } -static void give_base_to_objects(Main *mainvar, Scene *sce, Library *lib, const short idcode, const short is_link) +static void give_base_to_objects(Main *mainvar, Scene *sce, Library *lib, const short idcode, const short is_link, const short active_lay) { Object *ob; Base *base; @@ -10626,6 +10664,9 @@ static void give_base_to_objects(Main *mainvar, Scene *sce, Library *lib, const if (do_it) { base = MEM_callocN(sizeof(Base), "add_ext_base"); BLI_addtail(&sce->base, base); + + if (active_lay) ob->lay = sce->lay; + base->lay = ob->lay; base->object = ob; base->flag = ob->flag; @@ -10884,7 +10925,7 @@ static void library_append_end(const bContext *C, Main *mainl, FileData **fd, in /* don't instance anything when linking in scenes, assume the scene its self instances the data */ } else { - give_base_to_objects(mainvar, scene, curlib, idcode, is_link); + give_base_to_objects(mainvar, scene, curlib, idcode, is_link, flag & FILE_ACTIVELAY); if (flag & FILE_GROUP_INSTANCE) { give_base_to_groups(mainvar, scene); diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 24075a1fe58..3c6e646fe9c 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -1804,7 +1804,7 @@ static void write_meshs(WriteData *wd, ListBase *idbase) if (!save_for_old_blender) { #ifdef USE_BMESH_SAVE_WITHOUT_MFACE - Mesh backup_mesh = {{0}}; + Mesh backup_mesh = {{NULL}}; /* cache only - don't write */ backup_mesh.mface = mesh->mface; mesh->mface = NULL; @@ -1847,7 +1847,7 @@ static void write_meshs(WriteData *wd, ListBase *idbase) #ifdef USE_BMESH_SAVE_AS_COMPAT - Mesh backup_mesh = {{0}}; + Mesh backup_mesh = {{NULL}}; /* backup */ backup_mesh.mpoly = mesh->mpoly; @@ -2799,114 +2799,69 @@ static void write_nodetrees(WriteData *wd, ListBase *idbase) } #ifdef USE_NODE_COMPAT_CUSTOMNODES -static void customnodes_add_deprecated_nodetree_data(bNodeTree *ntree) -{ - bNodeLink *link, *last_link = ntree->links.last; - /* Forward compatibility for group nodes: add links to node tree interface sockets. - * These links are invalid by new rules (missing node pointer)! - * They will be removed again in customnodes_free_deprecated_data, - * cannot do this directly lest bNodeLink pointer mapping becomes ambiguous. - * When loading files with such links in a new Blender version - * they will be removed as well. - */ - for (link = ntree->links.first; link; link = link->next) { - bNode *fromnode = link->fromnode, *tonode = link->tonode; - bNodeSocket *fromsock = link->fromsock, *tosock = link->tosock; +static void customnodes_add_deprecated_data(Main *mainvar) +{ + FOREACH_NODETREE(mainvar, ntree, id) { + bNodeLink *link, *last_link = ntree->links.last; - /* check both sides of the link, to handle direct input-to-output links */ - if (fromnode->type == NODE_GROUP_INPUT) { - fromnode = NULL; - fromsock = ntreeFindSocketInterface(ntree, SOCK_IN, fromsock->identifier); - } - /* only the active output node defines links */ - if (tonode->type == NODE_GROUP_OUTPUT && (tonode->flag & NODE_DO_OUTPUT)) { - tonode = NULL; - tosock = ntreeFindSocketInterface(ntree, SOCK_OUT, tosock->identifier); - } + /* only do this for node groups */ + if (id != &ntree->id) + continue; - if (!fromnode || !tonode) { - /* Note: not using nodeAddLink here, it asserts existing node pointers */ - bNodeLink *tlink = MEM_callocN(sizeof(bNodeLink), "group node link"); - tlink->fromnode = fromnode; - tlink->fromsock = fromsock; - tlink->tonode = tonode; - tlink->tosock= tosock; - tosock->link = tlink; - tlink->flag |= NODE_LINK_VALID; - BLI_addtail(&ntree->links, tlink); + /* Forward compatibility for group nodes: add links to node tree interface sockets. + * These links are invalid by new rules (missing node pointer)! + * They will be removed again in customnodes_free_deprecated_data, + * cannot do this directly lest bNodeLink pointer mapping becomes ambiguous. + * When loading files with such links in a new Blender version + * they will be removed as well. + */ + for (link = ntree->links.first; link; link = link->next) { + bNode *fromnode = link->fromnode, *tonode = link->tonode; + bNodeSocket *fromsock = link->fromsock, *tosock = link->tosock; + + /* check both sides of the link, to handle direct input-to-output links */ + if (fromnode->type == NODE_GROUP_INPUT) { + fromnode = NULL; + fromsock = ntreeFindSocketInterface(ntree, SOCK_IN, fromsock->identifier); + } + /* only the active output node defines links */ + if (tonode->type == NODE_GROUP_OUTPUT && (tonode->flag & NODE_DO_OUTPUT)) { + tonode = NULL; + tosock = ntreeFindSocketInterface(ntree, SOCK_OUT, tosock->identifier); + } + + if (!fromnode || !tonode) { + /* Note: not using nodeAddLink here, it asserts existing node pointers */ + bNodeLink *tlink = MEM_callocN(sizeof(bNodeLink), "group node link"); + tlink->fromnode = fromnode; + tlink->fromsock = fromsock; + tlink->tonode = tonode; + tlink->tosock= tosock; + tosock->link = tlink; + tlink->flag |= NODE_LINK_VALID; + BLI_addtail(&ntree->links, tlink); + } + + /* don't check newly created compatibility links */ + if (link == last_link) + break; } - - /* don't check newly created compatibility links */ - if (link == last_link) - break; - } -} - -static void customnodes_add_deprecated_data(Main *mainvar) -{ - bNodeTree *ntree; - Scene *scene; - Material *mat; - World *world; - Lamp *lamp; - Tex *tex; - - for (ntree = mainvar->nodetree.first; ntree; ntree = ntree->id.next) - customnodes_add_deprecated_nodetree_data(ntree); - for (scene = mainvar->scene.first; scene; scene = scene->id.next) - if (scene->nodetree) - customnodes_add_deprecated_nodetree_data(scene->nodetree); - for (mat = mainvar->mat.first; mat; mat = mat->id.next) - if (mat->nodetree) - customnodes_add_deprecated_nodetree_data(mat->nodetree); - for (world = mainvar->world.first; world; world = world->id.next) - if (world->nodetree) - customnodes_add_deprecated_nodetree_data(world->nodetree); - for (lamp = mainvar->lamp.first; lamp; lamp = lamp->id.next) - if (lamp->nodetree) - customnodes_add_deprecated_nodetree_data(lamp->nodetree); - for (tex = mainvar->tex.first; tex; tex = tex->id.next) - if (tex->nodetree) - customnodes_add_deprecated_nodetree_data(tex->nodetree); -} - -static void customnodes_free_deprecated_nodetree_data(bNodeTree *ntree) -{ - bNodeLink *link, *next_link; - - for (link = ntree->links.first; link; link = next_link) { - next_link = link->next; - if (link->fromnode == NULL || link->tonode == NULL) - nodeRemLink(ntree, link); } + FOREACH_NODETREE_END } static void customnodes_free_deprecated_data(Main *mainvar) { - bNodeTree *ntree; - Scene *scene; - Material *mat; - World *world; - Lamp *lamp; - Tex *tex; - - for (ntree = mainvar->nodetree.first; ntree; ntree = ntree->id.next) - customnodes_free_deprecated_nodetree_data(ntree); - for (scene = mainvar->scene.first; scene; scene = scene->id.next) - if (scene->nodetree) - customnodes_free_deprecated_nodetree_data(scene->nodetree); - for (mat = mainvar->mat.first; mat; mat = mat->id.next) - if (mat->nodetree) - customnodes_free_deprecated_nodetree_data(mat->nodetree); - for (world = mainvar->world.first; world; world = world->id.next) - if (world->nodetree) - customnodes_free_deprecated_nodetree_data(world->nodetree); - for (lamp = mainvar->lamp.first; lamp; lamp = lamp->id.next) - if (lamp->nodetree) - customnodes_free_deprecated_nodetree_data(lamp->nodetree); - for (tex = mainvar->tex.first; tex; tex = tex->id.next) - if (tex->nodetree) - customnodes_free_deprecated_nodetree_data(tex->nodetree); + FOREACH_NODETREE(mainvar, ntree, id) { + bNodeLink *link, *next_link; + + for (link = ntree->links.first; link; link = next_link) { + next_link = link->next; + if (link->fromnode == NULL || link->tonode == NULL) + nodeRemLink(ntree, link); + } + } + FOREACH_NODETREE_END } #endif @@ -3323,8 +3278,11 @@ static int write_file_handle(Main *mainvar, int handle, MemFile *compare, MemFil #endif #ifdef USE_NODE_COMPAT_CUSTOMNODES - /* deprecated forward compat data is freed again below */ - customnodes_add_deprecated_data(mainvar); + /* don't write compatibility data on undo */ + if (!current) { + /* deprecated forward compat data is freed again below */ + customnodes_add_deprecated_data(mainvar); + } #endif sprintf(buf, "BLENDER%c%c%.3d", (sizeof(void*)==8)?'-':'_', (ENDIAN_ORDER==B_ENDIAN)?'V':'v', BLENDER_VERSION); @@ -3374,11 +3332,14 @@ static int write_file_handle(Main *mainvar, int handle, MemFile *compare, MemFil writedata(wd, DNA1, wd->sdna->datalen, wd->sdna->data); #ifdef USE_NODE_COMPAT_CUSTOMNODES - /* Ugly, forward compatibility code generates deprecated data during writing, - * this has to be freed again. Can not be done directly after writing, otherwise - * the data pointers could be reused and not be mapped correctly. - */ - customnodes_free_deprecated_data(mainvar); + /* compatibility data not created on undo */ + if (!current) { + /* Ugly, forward compatibility code generates deprecated data during writing, + * this has to be freed again. Can not be done directly after writing, otherwise + * the data pointers could be reused and not be mapped correctly. + */ + customnodes_free_deprecated_data(mainvar); + } #endif /* end of file */ |