diff options
Diffstat (limited to 'source/blender/blenloader/intern/readfile.c')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 76 |
1 files changed, 32 insertions, 44 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 5d0de6526b6..a7c625b0842 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -907,7 +907,10 @@ static void decode_blender_header(FileData *fd) } } -static int read_file_dna(FileData *fd) +/** + * \return Success if the file is read correctly, else set \a r_error_message. + */ +static bool read_file_dna(FileData *fd, const char **r_error_message) { BHead *bhead; @@ -915,20 +918,25 @@ static int read_file_dna(FileData *fd) if (bhead->code == DNA1) { const bool do_endian_swap = (fd->flags & FD_FLAGS_SWITCH_ENDIAN) != 0; - fd->filesdna = DNA_sdna_from_data(&bhead[1], bhead->len, do_endian_swap, true); + fd->filesdna = DNA_sdna_from_data(&bhead[1], bhead->len, do_endian_swap, true, r_error_message); if (fd->filesdna) { fd->compflags = DNA_struct_get_compareflags(fd->filesdna, fd->memsdna); /* used to retrieve ID names from (bhead+1) */ fd->id_name_offs = DNA_elem_offset(fd->filesdna, "ID", "char", "name[]"); + + return true; + } + else { + return false; } - return 1; } else if (bhead->code == ENDB) break; } - return 0; + *r_error_message = "Missing DNA block"; + return false; } static int *read_file_thumbnail(FileData *fd) @@ -1070,13 +1078,9 @@ static FileData *filedata_new(void) fd->filedes = -1; fd->gzfiledes = NULL; - - /* XXX, this doesn't need to be done all the time, - * but it keeps us re-entrant, remove once we have - * a lib that provides a nice lock. - zr - */ - fd->memsdna = DNA_sdna_from_data(DNAstr, DNAlen, false, false); - + + fd->memsdna = DNA_sdna_current_get(); + fd->datamap = oldnewmap_new(); fd->globmap = oldnewmap_new(); fd->libmap = oldnewmap_new(); @@ -1089,8 +1093,11 @@ static FileData *blo_decode_and_check(FileData *fd, ReportList *reports) decode_blender_header(fd); if (fd->flags & FD_FLAGS_FILE_OK) { - if (!read_file_dna(fd)) { - BKE_reportf(reports, RPT_ERROR, "Failed to read blend file '%s', incomplete", fd->relabase); + const char *error_message = NULL; + if (read_file_dna(fd, &error_message) == false) { + BKE_reportf(reports, RPT_ERROR, + "Failed to read blend file '%s': %s", + fd->relabase, error_message); blo_freefiledata(fd); fd = NULL; } @@ -1267,9 +1274,7 @@ void blo_freefiledata(FileData *fd) // Free all BHeadN data blocks BLI_freelistN(&fd->listbase); - - if (fd->memsdna) - DNA_sdna_free(fd->memsdna); + if (fd->filesdna) DNA_sdna_free(fd->filesdna); if (fd->compflags) @@ -1842,7 +1847,7 @@ void blo_add_library_pointer_map(ListBase *old_mainlist, FileData *fd) /* ********** END OLD POINTERS ****************** */ /* ********** READ FILE ****************** */ -static void switch_endian_structs(struct SDNA *filesdna, BHead *bhead) +static void switch_endian_structs(const struct SDNA *filesdna, BHead *bhead) { int blocksize, nblocks; char *data; @@ -2137,6 +2142,7 @@ static PreviewImage *direct_link_preview_image(FileData *fd, PreviewImage *old_p } prv->gputexture[i] = NULL; } + prv->icon_id = 0; } return prv; @@ -2705,7 +2711,7 @@ static void lib_link_node_socket(FileData *fd, ID *UNUSED(id), bNodeSocket *sock IDP_LibLinkProperty(sock->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); } -/* singe node tree (also used for material/scene trees), ntree is not NULL */ +/* Single node tree (also used for material/scene trees), ntree is not NULL */ static void lib_link_ntree(FileData *fd, ID *id, bNodeTree *ntree) { bNode *node; @@ -2748,22 +2754,6 @@ static void lib_link_nodetree(FileData *fd, Main *main) } } -/* get node tree stored locally in other IDs */ -static bNodeTree *nodetree_from_id(ID *id) -{ - if (!id) - return NULL; - switch (GS(id->name)) { - case ID_SCE: return ((Scene *)id)->nodetree; - case ID_MA: return ((Material *)id)->nodetree; - case ID_WO: return ((World *)id)->nodetree; - case ID_LA: return ((Lamp *)id)->nodetree; - case ID_TE: return ((Tex *)id)->nodetree; - case ID_LS: return ((FreestyleLineStyle *)id)->nodetree; - } - return NULL; -} - /* updates group node socket identifier so that * external links to/from the group node are preserved. */ @@ -5957,11 +5947,9 @@ static void lib_link_screen(FileData *fd, Main *main) snode->id = newlibadr(fd, sc->id.lib, snode->id); snode->from = newlibadr(fd, sc->id.lib, snode->from); - ntree = nodetree_from_id(snode->id); - if (ntree) - snode->nodetree = ntree; - else { - snode->nodetree = newlibadr_us(fd, sc->id.lib, snode->nodetree); + if (snode->id) { + ntree = ntreeFromID(snode->id); + snode->nodetree = ntree ? ntree : newlibadr_us(fd, sc->id.lib, snode->nodetree); } for (path = snode->treepath.first; path; path = path->next) { @@ -6341,11 +6329,11 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc snode->id = restore_pointer_by_name(id_map, snode->id, USER_REAL); snode->from = restore_pointer_by_name(id_map, snode->from, USER_IGNORE); - ntree = nodetree_from_id(snode->id); - if (ntree) - snode->nodetree = ntree; - else - snode->nodetree = restore_pointer_by_name(id_map, (ID*)snode->nodetree, USER_REAL); + if (snode->id) { + ntree = ntreeFromID(snode->id); + snode->nodetree = ntree ? ntree : + restore_pointer_by_name(id_map, (ID *)snode->nodetree, USER_REAL); + } for (path = snode->treepath.first; path; path = path->next) { if (path == snode->treepath.first) { |