diff options
Diffstat (limited to 'source/blender/blenloader')
16 files changed, 510 insertions, 185 deletions
diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt index 7eab0651d97..c56e0b5ad2e 100644 --- a/source/blender/blenloader/CMakeLists.txt +++ b/source/blender/blenloader/CMakeLists.txt @@ -98,3 +98,17 @@ blender_add_lib(bf_blenloader "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") # needed so writefile.c can use dna_type_offsets.h add_dependencies(bf_blenloader bf_dna) + +if(WITH_GTESTS) + set(TEST_SRC + tests/blendfile_loading_base_test.cc + tests/blendfile_load_test.cc + ) + set(TEST_INC + ) + set(TEST_LIB + bf_blenloader + ) + include(GTestTesting) + blender_add_test_lib(bf_blenloader_tests "${TEST_SRC}" "${INC};${TEST_INC}" "${INC_SYS}" "${LIB};${TEST_LIB}") +endif() diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c index cb2094d050f..888863dda06 100644 --- a/source/blender/blenloader/intern/readblenentry.c +++ b/source/blender/blenloader/intern/readblenentry.c @@ -102,28 +102,27 @@ void BLO_blendhandle_print_sizes(BlendHandle *bh, void *fp) if (bhead->code == ENDB) { break; } - else { - const short *sp = fd->filesdna->structs[bhead->SDNAnr]; - const char *name = fd->filesdna->types[sp[0]]; - char buf[4]; - - buf[0] = (bhead->code >> 24) & 0xFF; - buf[1] = (bhead->code >> 16) & 0xFF; - buf[2] = (bhead->code >> 8) & 0xFF; - buf[3] = (bhead->code >> 0) & 0xFF; - - buf[0] = buf[0] ? buf[0] : ' '; - buf[1] = buf[1] ? buf[1] : ' '; - buf[2] = buf[2] ? buf[2] : ' '; - buf[3] = buf[3] ? buf[3] : ' '; - - fprintf(fp, - "['%.4s', '%s', %d, %ld ],\n", - buf, - name, - bhead->nr, - (long int)(bhead->len + sizeof(BHead))); - } + + const short *sp = fd->filesdna->structs[bhead->SDNAnr]; + const char *name = fd->filesdna->types[sp[0]]; + char buf[4]; + + buf[0] = (bhead->code >> 24) & 0xFF; + buf[1] = (bhead->code >> 16) & 0xFF; + buf[2] = (bhead->code >> 8) & 0xFF; + buf[3] = (bhead->code >> 0) & 0xFF; + + buf[0] = buf[0] ? buf[0] : ' '; + buf[1] = buf[1] ? buf[1] : ' '; + buf[2] = buf[2] ? buf[2] : ' '; + buf[3] = buf[3] ? buf[3] : ' '; + + fprintf(fp, + "['%.4s', '%s', %d, %ld ],\n", + buf, + name, + bhead->nr, + (long int)(bhead->len + sizeof(BHead))); } fprintf(fp, "]\n"); } @@ -268,7 +267,7 @@ LinkNode *BLO_blendhandle_get_linkable_groups(BlendHandle *bh) if (bhead->code == ENDB) { break; } - else if (BKE_idtype_idcode_is_valid(bhead->code)) { + if (BKE_idtype_idcode_is_valid(bhead->code)) { if (BKE_idtype_idcode_is_linkable(bhead->code)) { const char *str = BKE_idtype_idcode_to_name(bhead->code); diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 134e23d36e8..42b97550db1 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -373,7 +373,7 @@ static void oldnewmap_insert_or_replace(OldNewMap *onm, OldNew entry) onm->nentries++; break; } - else if (onm->entries[index].oldp == entry.oldp) { + if (onm->entries[index].oldp == entry.oldp) { onm->entries[index] = entry; break; } @@ -1112,9 +1112,8 @@ static bool read_file_dna(FileData *fd, const char **r_error_message) return true; } - else { - return false; - } + + return false; } else if (bhead->code == ENDB) { break; @@ -1135,7 +1134,7 @@ static int *read_file_thumbnail(FileData *fd) const bool do_endian_swap = (fd->flags & FD_FLAGS_SWITCH_ENDIAN) != 0; int *data = (int *)(bhead + 1); - if (bhead->len < (2 * sizeof(int))) { + if (bhead->len < (sizeof(int[2]))) { break; } @@ -1156,7 +1155,7 @@ static int *read_file_thumbnail(FileData *fd) blend_thumb = data; break; } - else if (bhead->code != REND) { + if (bhead->code != REND) { /* Thumbnail is stored in TEST immediately after first REND... */ break; } @@ -1187,7 +1186,7 @@ static int fd_read_data_from_file(FileData *filedata, filedata->file_offset += readsize; } - return (readsize); + return readsize; } static off64_t fd_seek_data_from_file(FileData *filedata, off64_t offset, int whence) @@ -1212,7 +1211,7 @@ static int fd_read_gzip_from_file(FileData *filedata, filedata->file_offset += readsize; } - return (readsize); + return readsize; } /* Memory reading. */ @@ -1228,7 +1227,7 @@ static int fd_read_from_memory(FileData *filedata, memcpy(buffer, filedata->buffer + filedata->file_offset, readsize); filedata->file_offset += readsize; - return (readsize); + return readsize; } /* MemFile reading. */ @@ -1373,9 +1372,8 @@ static FileData *blo_filedata_from_file_descriptor(const char *filepath, errno ? strerror(errno) : TIP_("insufficient content")); return NULL; } - else { - BLI_lseek(file, 0, SEEK_SET); - } + + BLI_lseek(file, 0, SEEK_SET); /* Regular file. */ if (memcmp(header, "BLENDER", sizeof(header)) == 0) { @@ -1397,12 +1395,11 @@ static FileData *blo_filedata_from_file_descriptor(const char *filepath, errno ? strerror(errno) : TIP_("unknown error reading file")); return NULL; } - else { - /* 'seek_fn' is too slow for gzip, don't set it. */ - read_fn = fd_read_gzip_from_file; - /* Caller must close. */ - file = -1; - } + + /* 'seek_fn' is too slow for gzip, don't set it. */ + read_fn = fd_read_gzip_from_file; + /* Caller must close. */ + file = -1; } if (read_fn == NULL) { @@ -1487,14 +1484,14 @@ static int fd_read_gzip_from_memory(FileData *filedata, if (err == Z_STREAM_END) { return 0; } - else if (err != Z_OK) { + if (err != Z_OK) { printf("fd_read_gzip_from_memory: zlib error\n"); return 0; } filedata->file_offset += size; - return (size); + return size; } static int fd_read_gzip_from_memory_init(FileData *fd) @@ -1521,28 +1518,27 @@ FileData *blo_filedata_from_memory(const void *mem, int memsize, ReportList *rep BKE_report(reports, RPT_WARNING, (mem) ? TIP_("Unable to read") : TIP_("Unable to open")); return NULL; } - else { - FileData *fd = filedata_new(); - const char *cp = mem; - fd->buffer = mem; - fd->buffersize = memsize; + FileData *fd = filedata_new(); + const char *cp = mem; - /* test if gzip */ - if (cp[0] == 0x1f && cp[1] == 0x8b) { - if (0 == fd_read_gzip_from_memory_init(fd)) { - blo_filedata_free(fd); - return NULL; - } - } - else { - fd->read = fd_read_from_memory; + fd->buffer = mem; + fd->buffersize = memsize; + + /* test if gzip */ + if (cp[0] == 0x1f && cp[1] == 0x8b) { + if (0 == fd_read_gzip_from_memory_init(fd)) { + blo_filedata_free(fd); + return NULL; } + } + else { + fd->read = fd_read_from_memory; + } - fd->flags |= FD_FLAGS_NOT_MY_BUFFER; + fd->flags |= FD_FLAGS_NOT_MY_BUFFER; - return blo_decode_and_check(fd, reports); - } + return blo_decode_and_check(fd, reports); } FileData *blo_filedata_from_memfile(MemFile *memfile, @@ -1553,16 +1549,15 @@ FileData *blo_filedata_from_memfile(MemFile *memfile, BKE_report(reports, RPT_WARNING, "Unable to open blend <memory>"); return NULL; } - else { - FileData *fd = filedata_new(); - fd->memfile = memfile; - fd->undo_direction = params->undo_direction; - fd->read = fd_read_from_memfile; - fd->flags |= FD_FLAGS_NOT_MY_BUFFER; + FileData *fd = filedata_new(); + fd->memfile = memfile; + fd->undo_direction = params->undo_direction; - return blo_decode_and_check(fd, reports); - } + fd->read = fd_read_from_memfile; + fd->flags |= FD_FLAGS_NOT_MY_BUFFER; + + return blo_decode_and_check(fd, reports); } void blo_filedata_free(FileData *fd) @@ -1695,7 +1690,7 @@ bool BLO_library_path_explode(const char *path, char *r_dir, char **r_group, cha if (BLO_has_bfile_extension(r_dir) && BLI_is_file(r_dir)) { break; } - else if (STREQ(r_dir, BLO_EMBEDDED_STARTUP_BLEND)) { + if (STREQ(r_dir, BLO_EMBEDDED_STARTUP_BLEND)) { break; } @@ -4162,7 +4157,7 @@ static void direct_link_curve(BlendDataReader *reader, Curve *cu) direct_link_animdata(reader, cu->adt); /* Protect against integer overflow vulnerability. */ - CLAMP(cu->len_wchar, 0, INT_MAX - 4); + CLAMP(cu->len_char32, 0, INT_MAX - 4); BLO_read_pointer_array(reader, (void **)&cu->mat); @@ -5301,6 +5296,8 @@ static void direct_link_modifiers(BlendDataReader *reader, ListBase *lb, Object BLO_read_list(reader, lb); for (md = lb->first; md; md = md->next) { + BKE_modifier_session_uuid_generate(md); + md->error = NULL; md->runtime = NULL; @@ -5518,7 +5515,7 @@ static void direct_link_gpencil_modifiers(BlendDataReader *reader, ListBase *lb) if (gpmd->curve_intensity) { BKE_curvemapping_blend_read(reader, gpmd->curve_intensity); /* initialize the curve. Maybe this could be moved to modififer logic */ - BKE_curvemapping_initialize(gpmd->curve_intensity); + BKE_curvemapping_init(gpmd->curve_intensity); } } else if (md->type == eGpencilModifierType_Thick) { @@ -5527,7 +5524,7 @@ static void direct_link_gpencil_modifiers(BlendDataReader *reader, ListBase *lb) BLO_read_data_address(reader, &gpmd->curve_thickness); if (gpmd->curve_thickness) { BKE_curvemapping_blend_read(reader, gpmd->curve_thickness); - BKE_curvemapping_initialize(gpmd->curve_thickness); + BKE_curvemapping_init(gpmd->curve_thickness); } } else if (md->type == eGpencilModifierType_Tint) { @@ -5536,7 +5533,7 @@ static void direct_link_gpencil_modifiers(BlendDataReader *reader, ListBase *lb) BLO_read_data_address(reader, &gpmd->curve_intensity); if (gpmd->curve_intensity) { BKE_curvemapping_blend_read(reader, gpmd->curve_intensity); - BKE_curvemapping_initialize(gpmd->curve_intensity); + BKE_curvemapping_init(gpmd->curve_intensity); } } else if (md->type == eGpencilModifierType_Smooth) { @@ -5544,7 +5541,7 @@ static void direct_link_gpencil_modifiers(BlendDataReader *reader, ListBase *lb) BLO_read_data_address(reader, &gpmd->curve_intensity); if (gpmd->curve_intensity) { BKE_curvemapping_blend_read(reader, gpmd->curve_intensity); - BKE_curvemapping_initialize(gpmd->curve_intensity); + BKE_curvemapping_init(gpmd->curve_intensity); } } else if (md->type == eGpencilModifierType_Color) { @@ -5552,7 +5549,7 @@ static void direct_link_gpencil_modifiers(BlendDataReader *reader, ListBase *lb) BLO_read_data_address(reader, &gpmd->curve_intensity); if (gpmd->curve_intensity) { BKE_curvemapping_blend_read(reader, gpmd->curve_intensity); - BKE_curvemapping_initialize(gpmd->curve_intensity); + BKE_curvemapping_init(gpmd->curve_intensity); } } else if (md->type == eGpencilModifierType_Opacity) { @@ -5560,7 +5557,7 @@ static void direct_link_gpencil_modifiers(BlendDataReader *reader, ListBase *lb) BLO_read_data_address(reader, &gpmd->curve_intensity); if (gpmd->curve_intensity) { BKE_curvemapping_blend_read(reader, gpmd->curve_intensity); - BKE_curvemapping_initialize(gpmd->curve_intensity); + BKE_curvemapping_init(gpmd->curve_intensity); } } } @@ -6969,31 +6966,31 @@ static void direct_link_area(BlendDataReader *reader, ScrArea *area) BLO_read_data_address(reader, &snla->ads); } else if (sl->spacetype == SPACE_OUTLINER) { - SpaceOutliner *soops = (SpaceOutliner *)sl; + SpaceOutliner *space_outliner = (SpaceOutliner *)sl; /* use newdataadr_no_us and do not free old memory avoiding double * frees and use of freed memory. this could happen because of a * bug fixed in revision 58959 where the treestore memory address * was not unique */ - TreeStore *ts = newdataadr_no_us(reader->fd, soops->treestore); - soops->treestore = NULL; + TreeStore *ts = newdataadr_no_us(reader->fd, space_outliner->treestore); + space_outliner->treestore = NULL; if (ts) { TreeStoreElem *elems = newdataadr_no_us(reader->fd, ts->data); - soops->treestore = BLI_mempool_create( + space_outliner->treestore = BLI_mempool_create( sizeof(TreeStoreElem), ts->usedelem, 512, BLI_MEMPOOL_ALLOW_ITER); if (ts->usedelem && elems) { int i; for (i = 0; i < ts->usedelem; i++) { - TreeStoreElem *new_elem = BLI_mempool_alloc(soops->treestore); + TreeStoreElem *new_elem = BLI_mempool_alloc(space_outliner->treestore); *new_elem = elems[i]; } } /* we only saved what was used */ - soops->storeflag |= SO_TREESTORE_CLEANUP; // at first draw + space_outliner->storeflag |= SO_TREESTORE_CLEANUP; // at first draw } - soops->treehash = NULL; - soops->tree.first = soops->tree.last = NULL; + space_outliner->treehash = NULL; + space_outliner->tree.first = space_outliner->tree.last = NULL; } else if (sl->spacetype == SPACE_IMAGE) { SpaceImage *sima = (SpaceImage *)sl; @@ -7220,20 +7217,20 @@ static void lib_link_area(BlendLibReader *reader, ID *parent_id, ScrArea *area) break; } case SPACE_OUTLINER: { - SpaceOutliner *so = (SpaceOutliner *)sl; - BLO_read_id_address(reader, NULL, &so->search_tse.id); + SpaceOutliner *space_outliner = (SpaceOutliner *)sl; + BLO_read_id_address(reader, NULL, &space_outliner->search_tse.id); - if (so->treestore) { + if (space_outliner->treestore) { TreeStoreElem *tselem; BLI_mempool_iter iter; - BLI_mempool_iternew(so->treestore, &iter); + BLI_mempool_iternew(space_outliner->treestore, &iter); while ((tselem = BLI_mempool_iterstep(&iter))) { BLO_read_id_address(reader, NULL, &tselem->id); } - if (so->treehash) { + if (space_outliner->treehash) { /* rebuild hash table, because it depends on ids too */ - so->storeflag |= SO_TREESTORE_REBUILD; + space_outliner->storeflag |= SO_TREESTORE_REBUILD; } } break; @@ -7792,15 +7789,16 @@ static void lib_link_workspace_layout_restore(struct IDNameLib_Map *id_map, } } else if (sl->spacetype == SPACE_OUTLINER) { - SpaceOutliner *so = (SpaceOutliner *)sl; + SpaceOutliner *space_outliner = (SpaceOutliner *)sl; - so->search_tse.id = restore_pointer_by_name(id_map, so->search_tse.id, USER_IGNORE); + space_outliner->search_tse.id = restore_pointer_by_name( + id_map, space_outliner->search_tse.id, USER_IGNORE); - if (so->treestore) { + if (space_outliner->treestore) { TreeStoreElem *tselem; BLI_mempool_iter iter; - BLI_mempool_iternew(so->treestore, &iter); + BLI_mempool_iternew(space_outliner->treestore, &iter); while ((tselem = BLI_mempool_iterstep(&iter))) { /* Do not try to restore pointers to drivers/sequence/etc., * can crash in undo case! */ @@ -7811,9 +7809,9 @@ static void lib_link_workspace_layout_restore(struct IDNameLib_Map *id_map, tselem->id = NULL; } } - if (so->treehash) { + if (space_outliner->treehash) { /* rebuild hash table, because it depends on ids too */ - so->storeflag |= SO_TREESTORE_REBUILD; + space_outliner->storeflag |= SO_TREESTORE_REBUILD; } } } @@ -8695,9 +8693,8 @@ static void direct_link_volume(BlendDataReader *reader, Volume *volume) static void lib_link_simulation(BlendLibReader *reader, Simulation *simulation) { - LISTBASE_FOREACH ( - PersistentDataHandleItem *, handle_item, &simulation->persistent_data_handles) { - BLO_read_id_address(reader, simulation->id.lib, &handle_item->id); + LISTBASE_FOREACH (SimulationDependency *, dependency, &simulation->dependencies) { + BLO_read_id_address(reader, simulation->id.lib, &dependency->id); } } @@ -8716,7 +8713,7 @@ static void direct_link_simulation(BlendDataReader *reader, Simulation *simulati } } - BLO_read_list(reader, &simulation->persistent_data_handles); + BLO_read_list(reader, &simulation->dependencies); } /** \} */ @@ -9254,17 +9251,16 @@ static bool read_libblock_undo_restore( *r_id_old = id_old; return true; } - else if (id_old != NULL) { + if (id_old != NULL) { /* Local datablock was changed. Restore at the address of the old datablock. */ DEBUG_PRINTF("read to old existing address\n"); *r_id_old = id_old; return false; } - else { - /* Local datablock does not exist in the undo step, so read from scratch. */ - DEBUG_PRINTF("read at new address\n"); - return false; - } + + /* Local datablock does not exist in the undo step, so read from scratch. */ + DEBUG_PRINTF("read at new address\n"); + return false; } /* This routine reads a datablock and its direct data, and advances bhead to @@ -10035,7 +10031,7 @@ static int verg_bheadsort(const void *v1, const void *v2) if (x1->old > x2->old) { return 1; } - else if (x1->old < x2->old) { + if (x1->old < x2->old) { return -1; } return 0; @@ -11125,9 +11121,8 @@ static void expand_simulation(BlendExpander *expander, Simulation *simulation) if (simulation->adt) { expand_animdata(expander, simulation->adt); } - LISTBASE_FOREACH ( - PersistentDataHandleItem *, handle_item, &simulation->persistent_data_handles) { - BLO_expand(expander, handle_item->id); + LISTBASE_FOREACH (SimulationDependency *, dependency, &simulation->dependencies) { + BLO_expand(expander, dependency->id); } } diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c index 3ed59a0baa1..0e753c84476 100644 --- a/source/blender/blenloader/intern/versioning_250.c +++ b/source/blender/blenloader/intern/versioning_250.c @@ -270,9 +270,9 @@ static void area_add_window_regions(ScrArea *area, SpaceLink *sl, ListBase *lb) break; case SPACE_OUTLINER: { - SpaceOutliner *soops = (SpaceOutliner *)sl; + SpaceOutliner *space_outliner = (SpaceOutliner *)sl; - memcpy(®ion->v2d, &soops->v2d, sizeof(View2D)); + memcpy(®ion->v2d, &space_outliner->v2d, sizeof(View2D)); region->v2d.scroll &= ~V2D_SCROLL_LEFT; region->v2d.scroll |= (V2D_SCROLL_RIGHT | V2D_SCROLL_BOTTOM); @@ -280,7 +280,7 @@ static void area_add_window_regions(ScrArea *area, SpaceLink *sl, ListBase *lb) region->v2d.keepzoom |= (V2D_LOCKZOOM_X | V2D_LOCKZOOM_Y | V2D_KEEPASPECT); region->v2d.keeptot = V2D_KEEPTOT_STRICT; region->v2d.minzoom = region->v2d.maxzoom = 1.0f; - // region->v2d.flag |= V2D_IS_INITIALISED; + // region->v2d.flag |= V2D_IS_INIT; break; } case SPACE_GRAPH: { @@ -297,7 +297,7 @@ static void area_add_window_regions(ScrArea *area, SpaceLink *sl, ListBase *lb) region->v2d.max[0] = MAXFRAMEF; region->v2d.max[1] = FLT_MAX; - // region->v2d.flag |= V2D_IS_INITIALISED; + // region->v2d.flag |= V2D_IS_INIT; break; } case SPACE_NLA: { @@ -355,7 +355,7 @@ static void area_add_window_regions(ScrArea *area, SpaceLink *sl, ListBase *lb) region->v2d.scroll |= (V2D_SCROLL_BOTTOM | V2D_SCROLL_HORIZONTAL_HANDLES); region->v2d.scroll |= (V2D_SCROLL_LEFT | V2D_SCROLL_VERTICAL_HANDLES); region->v2d.align = V2D_ALIGN_NO_NEG_Y; - region->v2d.flag |= V2D_IS_INITIALISED; + region->v2d.flag |= V2D_IS_INIT; break; } case SPACE_NODE: { @@ -635,6 +635,7 @@ static void do_versions_socket_default_value_259(bNodeSocket *sock) } } +/* NOLINTNEXTLINE: readability-function-size */ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) { /* WATCH IT!!!: pointers from libdata have not been converted */ @@ -965,7 +966,7 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) bPoseChannel *pchan; for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { - /* just need to initialise rotation axis properly... */ + /* Just need to initialize rotation axis properly. */ pchan->rotAxis[1] = 1.0f; } } diff --git a/source/blender/blenloader/intern/versioning_260.c b/source/blender/blenloader/intern/versioning_260.c index b3bf8991c3e..1ac90398c0a 100644 --- a/source/blender/blenloader/intern/versioning_260.c +++ b/source/blender/blenloader/intern/versioning_260.c @@ -658,6 +658,7 @@ static void do_versions_nodetree_customnodes(bNodeTree *ntree, int UNUSED(is_gro } } +/* NOLINTNEXTLINE: readability-function-size */ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) { if (bmain->versionfile < 260) { @@ -1205,7 +1206,7 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) if (region->regiontype == RGN_TYPE_PREVIEW) { if (region->alignment != RGN_ALIGN_NONE) { region->flag |= RGN_FLAG_HIDDEN; - region->v2d.flag &= ~V2D_IS_INITIALISED; + region->v2d.flag &= ~V2D_IS_INIT; region->alignment = RGN_ALIGN_NONE; hide = true; @@ -2348,10 +2349,14 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) for (area = screen->areabase.first; area; area = area->next) { for (sl = area->spacedata.first; sl; sl = sl->next) { if (sl->spacetype == SPACE_OUTLINER) { - SpaceOutliner *so = (SpaceOutliner *)sl; - - if (!ELEM(so->outlinevis, SO_SCENES, SO_LIBRARIES, SO_SEQUENCE, SO_DATA_API)) { - so->outlinevis = SO_SCENES; + SpaceOutliner *space_outliner = (SpaceOutliner *)sl; + + if (!ELEM(space_outliner->outlinevis, + SO_SCENES, + SO_LIBRARIES, + SO_SEQUENCE, + SO_DATA_API)) { + space_outliner->outlinevis = SO_SCENES; } } } @@ -2520,7 +2525,7 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) for (cu = bmain->curves.first; cu; cu = cu->id.next) { if (cu->str) { - cu->len_wchar = BLI_strlen_utf8(cu->str); + cu->len_char32 = BLI_strlen_utf8(cu->str); } } } diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index 521fc4b9b82..b19c6221391 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -242,7 +242,7 @@ static void do_version_action_editor_properties_region(ListBase *regionbase) /* already exists */ return; } - else if (region->regiontype == RGN_TYPE_WINDOW) { + if (region->regiontype == RGN_TYPE_WINDOW) { /* add new region here */ ARegion *arnew = MEM_callocN(sizeof(ARegion), "buttons for action"); @@ -377,9 +377,8 @@ static char *replace_bbone_easing_rnapath(char *old_path) MEM_freeN(old_path); return new_path; } - else { - return old_path; - } + + return old_path; } static void do_version_bbone_easing_fcurve_fix(ID *UNUSED(id), @@ -421,6 +420,7 @@ static void do_version_bbone_easing_fcurve_fix(ID *UNUSED(id), } } +/* NOLINTNEXTLINE: readability-function-size */ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) { if (!MAIN_VERSION_ATLEAST(bmain, 270, 0)) { @@ -1108,7 +1108,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) for (scene = bmain->scenes.first; scene != NULL; scene = scene->id.next) { CurveMapping *curve_mapping = &scene->r.mblur_shutter_curve; BKE_curvemapping_set_defaults(curve_mapping, 1, 0.0f, 0.0f, 1.0f, 1.0f); - BKE_curvemapping_initialize(curve_mapping); + BKE_curvemapping_init(curve_mapping); BKE_curvemap_reset( curve_mapping->cm, &curve_mapping->clipr, CURVE_PRESET_MAX, CURVEMAP_SLOPE_POS_NEG); } diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index 51df61143e0..0d8f2eac99e 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -190,7 +190,7 @@ static void do_version_workspaces_create_from_screens(Main *bmain) static void do_version_area_change_space_to_space_action(ScrArea *area, const Scene *scene) { SpaceType *stype = BKE_spacetype_from_id(SPACE_ACTION); - SpaceAction *saction = (SpaceAction *)stype->new (area, scene); + SpaceAction *saction = (SpaceAction *)stype->create(area, scene); ARegion *region_channels; /* Properly free current regions */ @@ -1201,7 +1201,7 @@ static void do_version_fcurve_hide_viewport_fix(struct ID *UNUSED(id), struct FCurve *fcu, void *UNUSED(user_data)) { - if (strcmp(fcu->rna_path, "hide")) { + if (!STREQ(fcu->rna_path, "hide")) { return; } @@ -1282,20 +1282,20 @@ void do_versions_after_linking_280(Main *bmain, ReportList *UNUSED(reports)) LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { LISTBASE_FOREACH (SpaceLink *, space, &area->spacedata) { if (space->spacetype == SPACE_OUTLINER) { - SpaceOutliner *soutliner = (SpaceOutliner *)space; + SpaceOutliner *space_outliner = (SpaceOutliner *)space; - soutliner->outlinevis = SO_VIEW_LAYER; + space_outliner->outlinevis = SO_VIEW_LAYER; if (BLI_listbase_count_at_most(&layer->layer_collections, 2) == 1) { - if (soutliner->treestore == NULL) { - soutliner->treestore = BLI_mempool_create( + if (space_outliner->treestore == NULL) { + space_outliner->treestore = BLI_mempool_create( sizeof(TreeStoreElem), 1, 512, BLI_MEMPOOL_ALLOW_ITER); } /* Create a tree store element for the collection. This is normally * done in check_persistent (outliner_tree.c), but we need to access * it here :/ (expand element if it's the only one) */ - TreeStoreElem *tselem = BLI_mempool_calloc(soutliner->treestore); + TreeStoreElem *tselem = BLI_mempool_calloc(space_outliner->treestore); tselem->type = TSE_LAYER_COLLECTION; tselem->id = layer->layer_collections.first; tselem->nr = tselem->used = 0; @@ -1792,6 +1792,7 @@ static void do_versions_seq_set_cache_defaults(Editing *ed) ed->recycle_max_cost = 10.0f; } +/* NOLINTNEXTLINE: readability-function-size */ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) { bool use_collection_compat_28 = true; @@ -1958,7 +1959,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) GP_Sculpt_Settings *gset = &scene->toolsettings->gp_sculpt; if ((gset) && (gset->cur_falloff == NULL)) { gset->cur_falloff = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); - BKE_curvemapping_initialize(gset->cur_falloff); + BKE_curvemapping_init(gset->cur_falloff); BKE_curvemap_reset(gset->cur_falloff->cm, &gset->cur_falloff->clipr, CURVE_PRESET_GAUSS, @@ -2024,15 +2025,15 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) for (area = screen->areabase.first; area; area = area->next) { for (sl = area->spacedata.first; sl; sl = sl->next) { if (sl->spacetype == SPACE_OUTLINER) { - SpaceOutliner *so = (SpaceOutliner *)sl; + SpaceOutliner *space_outliner = (SpaceOutliner *)sl; - if (!ELEM(so->outlinevis, + if (!ELEM(space_outliner->outlinevis, SO_SCENES, SO_LIBRARIES, SO_SEQUENCE, SO_DATA_API, SO_ID_ORPHANS)) { - so->outlinevis = SO_VIEW_LAYER; + space_outliner->outlinevis = SO_VIEW_LAYER; } } } @@ -2412,9 +2413,9 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { if (sl->spacetype == SPACE_OUTLINER) { - SpaceOutliner *soops = (SpaceOutliner *)sl; - soops->filter_id_type = ID_GR; - soops->outlinevis = SO_VIEW_LAYER; + SpaceOutliner *space_outliner = (SpaceOutliner *)sl; + space_outliner->filter_id_type = ID_GR; + space_outliner->outlinevis = SO_VIEW_LAYER; } } } @@ -3341,7 +3342,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { if (sl->spacetype == SPACE_VIEW3D) { View3D *v3d = (View3D *)sl; - memcpy(v3d->shading.lookdev_light, v3d->shading.studio_light, sizeof(char) * 256); + memcpy(v3d->shading.lookdev_light, v3d->shading.studio_light, sizeof(char[256])); } } } @@ -3371,7 +3372,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) GP_Sculpt_Settings *gset = &scene->toolsettings->gp_sculpt; if ((gset) && (gset->cur_primitive == NULL)) { gset->cur_primitive = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); - BKE_curvemapping_initialize(gset->cur_primitive); + BKE_curvemapping_init(gset->cur_primitive); BKE_curvemap_reset(gset->cur_primitive->cm, &gset->cur_primitive->clipr, CURVE_PRESET_BELL, @@ -3411,9 +3412,10 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) break; } case SPACE_OUTLINER: { - SpaceOutliner *so = (SpaceOutliner *)sl; - so->filter &= ~(SO_FILTER_UNUSED_1 | SO_FILTER_UNUSED_5 | SO_FILTER_UNUSED_12); - so->storeflag &= ~(SO_TREESTORE_UNUSED_1); + SpaceOutliner *space_outliner = (SpaceOutliner *)sl; + space_outliner->filter &= ~(SO_FILTER_UNUSED_1 | SO_FILTER_UNUSED_5 | + SO_FILTER_UNUSED_12); + space_outliner->storeflag &= ~(SO_TREESTORE_UNUSED_1); break; } case SPACE_FILE: { @@ -4027,9 +4029,9 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) if (sl->spacetype != SPACE_OUTLINER) { continue; } - SpaceOutliner *so = (SpaceOutliner *)sl; - so->filter &= ~SO_FLAG_UNUSED_1; - so->show_restrict_flags = SO_RESTRICT_ENABLE | SO_RESTRICT_HIDE; + SpaceOutliner *space_outliner = (SpaceOutliner *)sl; + space_outliner->filter &= ~SO_FLAG_UNUSED_1; + space_outliner->show_restrict_flags = SO_RESTRICT_ENABLE | SO_RESTRICT_HIDE; } } } @@ -4161,9 +4163,9 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) } /* Mark outliners as dirty for syncing and enable synced selection */ if (sl->spacetype == SPACE_OUTLINER) { - SpaceOutliner *soutliner = (SpaceOutliner *)sl; - soutliner->sync_select_dirty |= WM_OUTLINER_SYNC_SELECT_FROM_ALL; - soutliner->flag |= SO_SYNC_SELECT; + SpaceOutliner *space_outliner = (SpaceOutliner *)sl; + space_outliner->sync_select_dirty |= WM_OUTLINER_SYNC_SELECT_FROM_ALL; + space_outliner->flag |= SO_SYNC_SELECT; } } } @@ -4767,7 +4769,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) if (mmd->curve_intensity == NULL) { mmd->curve_intensity = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); if (mmd->curve_intensity) { - BKE_curvemapping_initialize(mmd->curve_intensity); + BKE_curvemapping_init(mmd->curve_intensity); } } break; @@ -4778,7 +4780,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) if (mmd->curve_intensity == NULL) { mmd->curve_intensity = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); if (mmd->curve_intensity) { - BKE_curvemapping_initialize(mmd->curve_intensity); + BKE_curvemapping_init(mmd->curve_intensity); } } break; @@ -4788,7 +4790,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) if (mmd->curve_intensity == NULL) { mmd->curve_intensity = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); if (mmd->curve_intensity) { - BKE_curvemapping_initialize(mmd->curve_intensity); + BKE_curvemapping_init(mmd->curve_intensity); } } break; @@ -4798,7 +4800,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) if (mmd->curve_intensity == NULL) { mmd->curve_intensity = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); if (mmd->curve_intensity) { - BKE_curvemapping_initialize(mmd->curve_intensity); + BKE_curvemapping_init(mmd->curve_intensity); } } break; @@ -4808,7 +4810,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) if (mmd->curve_intensity == NULL) { mmd->curve_intensity = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); if (mmd->curve_intensity) { - BKE_curvemapping_initialize(mmd->curve_intensity); + BKE_curvemapping_init(mmd->curve_intensity); } } break; diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c index a96b82e2e91..12b5a297df5 100644 --- a/source/blender/blenloader/intern/versioning_290.c +++ b/source/blender/blenloader/intern/versioning_290.c @@ -22,9 +22,11 @@ #include "BLI_listbase.h" #include "BLI_math.h" +#include "BLI_string.h" #include "BLI_utildefines.h" #include "DNA_brush_types.h" +#include "DNA_cachefile_types.h" #include "DNA_constraint_types.h" #include "DNA_genfile.h" #include "DNA_gpencil_modifier_types.h" @@ -446,5 +448,39 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain) } } } + + /* Initialise additional velocity parameter for CacheFiles. */ + if (!DNA_struct_elem_find( + fd->filesdna, "MeshSeqCacheModifierData", "float", "velocity_scale")) { + for (Object *object = bmain->objects.first; object != NULL; object = object->id.next) { + LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) { + if (md->type == eModifierType_MeshSequenceCache) { + MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md; + mcmd->velocity_scale = 1.0f; + mcmd->vertex_velocities = NULL; + mcmd->num_vertices = 0; + } + } + } + } + + if (!DNA_struct_elem_find(fd->filesdna, "CacheFile", "char", "velocity_unit")) { + for (CacheFile *cache_file = bmain->cachefiles.first; cache_file != NULL; + cache_file = cache_file->id.next) { + BLI_strncpy(cache_file->velocity_name, ".velocities", sizeof(cache_file->velocity_name)); + cache_file->velocity_unit = CACHEFILE_VELOCITY_UNIT_SECOND; + } + } + + if (!DNA_struct_elem_find(fd->filesdna, "OceanModifierData", "int", "viewport_resolution")) { + for (Object *object = bmain->objects.first; object != NULL; object = object->id.next) { + LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) { + if (md->type == eModifierType_Ocean) { + OceanModifierData *omd = (OceanModifierData *)md; + omd->viewport_resolution = omd->resolution; + } + } + } + } } } diff --git a/source/blender/blenloader/intern/versioning_cycles.c b/source/blender/blenloader/intern/versioning_cycles.c index 46faddf6e5a..26329fca6fa 100644 --- a/source/blender/blenloader/intern/versioning_cycles.c +++ b/source/blender/blenloader/intern/versioning_cycles.c @@ -1447,7 +1447,7 @@ void do_versions_after_linking_cycles(Main *bmain) if (is_fstop) { continue; } - else if (aperture_size > 0.0f) { + if (aperture_size > 0.0f) { if (camera->type == CAM_ORTHO) { camera->dof.aperture_fstop = 1.0f / (2.0f * aperture_size); } diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c index 7f75c0100b8..b4bee9a3c7e 100644 --- a/source/blender/blenloader/intern/versioning_defaults.c +++ b/source/blender/blenloader/intern/versioning_defaults.c @@ -106,7 +106,7 @@ static void blo_update_defaults_screen(bScreen *screen, /* Some toolbars have been saved as initialized, * we don't want them to have odd zoom-level or scrolling set, see: T47047 */ if (ELEM(region->regiontype, RGN_TYPE_UI, RGN_TYPE_TOOLS, RGN_TYPE_TOOL_PROPS)) { - region->v2d.flag &= ~V2D_IS_INITIALISED; + region->v2d.flag &= ~V2D_IS_INIT; } } @@ -174,7 +174,7 @@ static void blo_update_defaults_screen(bScreen *screen, } else if (area->spacetype == SPACE_SEQ) { SpaceSeq *seq = area->spacedata.first; - seq->flag |= SEQ_SHOW_MARKERS | SEQ_SHOW_FCURVES; + seq->flag |= SEQ_SHOW_MARKERS | SEQ_SHOW_FCURVES | SEQ_ZOOM_TO_FIT; } else if (area->spacetype == SPACE_TEXT) { /* Show syntax and line numbers in Script workspace text editor. */ @@ -326,7 +326,7 @@ static void blo_update_defaults_scene(Main *bmain, Scene *scene) if (ts->gp_sculpt.cur_falloff == NULL) { ts->gp_sculpt.cur_falloff = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); CurveMapping *gp_falloff_curve = ts->gp_sculpt.cur_falloff; - BKE_curvemapping_initialize(gp_falloff_curve); + BKE_curvemapping_init(gp_falloff_curve); BKE_curvemap_reset(gp_falloff_curve->cm, &gp_falloff_curve->clipr, CURVE_PRESET_GAUSS, @@ -335,7 +335,7 @@ static void blo_update_defaults_scene(Main *bmain, Scene *scene) if (ts->gp_sculpt.cur_primitive == NULL) { ts->gp_sculpt.cur_primitive = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); CurveMapping *gp_primitive_curve = ts->gp_sculpt.cur_primitive; - BKE_curvemapping_initialize(gp_primitive_curve); + BKE_curvemapping_init(gp_primitive_curve); BKE_curvemap_reset(gp_primitive_curve->cm, &gp_primitive_curve->clipr, CURVE_PRESET_BELL, @@ -698,6 +698,14 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template) brush->sculpt_tool = SCULPT_TOOL_SMEAR; } + brush_name = "Boundary"; + brush = BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2); + if (!brush) { + brush = BKE_brush_add(bmain, brush_name, OB_MODE_SCULPT); + id_us_min(&brush->id); + brush->sculpt_tool = SCULPT_TOOL_BOUNDARY; + } + brush_name = "Simplify"; brush = BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2); if (!brush) { @@ -714,6 +722,14 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template) brush->sculpt_tool = SCULPT_TOOL_DRAW_FACE_SETS; } + brush_name = "Multires Displacement Eraser"; + brush = BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2); + if (!brush) { + brush = BKE_brush_add(bmain, brush_name, OB_MODE_SCULPT); + id_us_min(&brush->id); + brush->sculpt_tool = SCULPT_TOOL_DISPLACEMENT_ERASER; + } + /* Use the same tool icon color in the brush cursor */ for (brush = bmain->brushes.first; brush; brush = brush->id.next) { if (brush->ob_mode & OB_MODE_SCULPT) { diff --git a/source/blender/blenloader/intern/versioning_legacy.c b/source/blender/blenloader/intern/versioning_legacy.c index 44c7c35e47d..88ccb551e16 100644 --- a/source/blender/blenloader/intern/versioning_legacy.c +++ b/source/blender/blenloader/intern/versioning_legacy.c @@ -102,7 +102,7 @@ static void vcol_to_fcol(Mesh *me) return; } - mcoln = mcolmain = MEM_malloc_arrayN(me->totface, 4 * sizeof(int), "mcoln"); + mcoln = mcolmain = MEM_malloc_arrayN(me->totface, sizeof(int[4]), "mcoln"); mcol = (uint *)me->mcol; mface = me->mface; for (a = me->totface; a > 0; a--, mface++) { @@ -493,6 +493,7 @@ void blo_do_version_old_trackto_to_constraints(Object *ob) ob->track = NULL; } +/* NOLINTNEXTLINE: readability-function-size */ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) { /* WATCH IT!!!: pointers from libdata have not been converted */ @@ -2096,7 +2097,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) if (la->curfalloff == NULL) { la->curfalloff = BKE_curvemapping_add(1, 0.0f, 1.0f, 1.0f, 0.0f); - BKE_curvemapping_initialize(la->curfalloff); + BKE_curvemapping_init(la->curfalloff); } } } diff --git a/source/blender/blenloader/intern/versioning_userdef.c b/source/blender/blenloader/intern/versioning_userdef.c index 50e3b375166..e2dc27d7e88 100644 --- a/source/blender/blenloader/intern/versioning_userdef.c +++ b/source/blender/blenloader/intern/versioning_userdef.c @@ -366,7 +366,7 @@ void BLO_version_defaults_userpref_blend(Main *bmain, UserDef *userdef) } if (!USER_VERSION_ATLEAST(250, 0)) { /* adjust grease-pencil distances */ - userdef->gp_manhattendist = 1; + userdef->gp_manhattandist = 1; userdef->gp_euclideandist = 2; /* adjust default interpolation for new IPO-curves */ diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 6f9f3eec31d..ed4f997a856 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -241,9 +241,8 @@ static bool ww_open_none(WriteWrap *ww, const char *filepath) FILE_HANDLE(ww) = file; return true; } - else { - return false; - } + + return false; } static bool ww_close_none(WriteWrap *ww) { @@ -268,9 +267,8 @@ static bool ww_open_zlib(WriteWrap *ww, const char *filepath) FILE_HANDLE(ww) = file; return true; } - else { - return false; - } + + return false; } static bool ww_close_zlib(WriteWrap *ww) { @@ -2015,7 +2013,7 @@ static void write_curve(BlendWriter *writer, Curve *cu, const void *id_address) if (cu->vfont) { BLO_write_raw(writer, cu->len + 1, cu->str); - BLO_write_struct_array(writer, CharInfo, cu->len_wchar + 1, cu->strinfo); + BLO_write_struct_array(writer, CharInfo, cu->len_char32 + 1, cu->strinfo); BLO_write_struct_array(writer, TextBox, cu->totbox, cu->tb); } else { @@ -2848,12 +2846,12 @@ static void write_uilist(BlendWriter *writer, uiList *ui_list) } } -static void write_soops(BlendWriter *writer, SpaceOutliner *so) +static void write_space_outliner(BlendWriter *writer, SpaceOutliner *space_outliner) { - BLI_mempool *ts = so->treestore; + BLI_mempool *ts = space_outliner->treestore; if (ts) { - SpaceOutliner so_flat = *so; + SpaceOutliner space_outliner_flat = *space_outliner; int elems = BLI_mempool_len(ts); /* linearize mempool to array */ @@ -2874,7 +2872,7 @@ static void write_soops(BlendWriter *writer, SpaceOutliner *so) ts_flat.totelem = elems; ts_flat.data = data_addr; - BLO_write_struct(writer, SpaceOutliner, so); + BLO_write_struct(writer, SpaceOutliner, space_outliner); BLO_write_struct_at_address(writer, TreeStore, ts, &ts_flat); BLO_write_struct_array_at_address(writer, TreeStoreElem, elems, data_addr, data); @@ -2882,12 +2880,12 @@ static void write_soops(BlendWriter *writer, SpaceOutliner *so) MEM_freeN(data); } else { - so_flat.treestore = NULL; - BLO_write_struct_at_address(writer, SpaceOutliner, so, &so_flat); + space_outliner_flat.treestore = NULL; + BLO_write_struct_at_address(writer, SpaceOutliner, space_outliner, &space_outliner_flat); } } else { - BLO_write_struct(writer, SpaceOutliner, so); + BLO_write_struct(writer, SpaceOutliner, space_outliner); } } @@ -2963,8 +2961,8 @@ static void write_area_regions(BlendWriter *writer, ScrArea *area) BLO_write_struct(writer, SpaceSeq, sl); } else if (sl->spacetype == SPACE_OUTLINER) { - SpaceOutliner *so = (SpaceOutliner *)sl; - write_soops(writer, so); + SpaceOutliner *space_outliner = (SpaceOutliner *)sl; + write_space_outliner(writer, space_outliner); } else if (sl->spacetype == SPACE_IMAGE) { BLO_write_struct(writer, SpaceImage, sl); @@ -3875,7 +3873,7 @@ static void write_simulation(BlendWriter *writer, Simulation *simulation, const } } - BLO_write_struct_list(writer, PersistentDataHandleItem, &simulation->persistent_data_handles); + BLO_write_struct_list(writer, SimulationDependency, &simulation->dependencies); } } @@ -4060,8 +4058,9 @@ static bool write_file_handle(Main *mainvar, * avoid thumbnail detecting changes because of this. */ mywrite_flush(wd); - OverrideLibraryStorage *override_storage = - wd->use_memfile ? NULL : BKE_lib_override_library_operations_store_initialize(); + OverrideLibraryStorage *override_storage = wd->use_memfile ? + NULL : + BKE_lib_override_library_operations_store_init(); #define ID_BUFFER_STATIC_SIZE 8192 /* This outer loop allows to save first data-blocks from real mainvar, @@ -4612,7 +4611,7 @@ void BLO_write_pointer_array(BlendWriter *writer, int size, const void *data_ptr void BLO_write_float3_array(BlendWriter *writer, int size, const float *data_ptr) { - BLO_write_raw(writer, sizeof(float) * 3 * size, data_ptr); + BLO_write_raw(writer, sizeof(float[3]) * size, data_ptr); } /** diff --git a/source/blender/blenloader/tests/blendfile_load_test.cc b/source/blender/blenloader/tests/blendfile_load_test.cc new file mode 100644 index 00000000000..2ba3e3fcd88 --- /dev/null +++ b/source/blender/blenloader/tests/blendfile_load_test.cc @@ -0,0 +1,31 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2019 by Blender Foundation. + */ +#include "blendfile_loading_base_test.h" + +class BlendfileLoadingTest : public BlendfileLoadingBaseTest { +}; + +TEST_F(BlendfileLoadingTest, CanaryTest) +{ + /* Load the smallest blend file we have in the SVN lib/tests directory. */ + if (!blendfile_load("modifier_stack/array_test.blend")) { + return; + } + depsgraph_create(DAG_EVAL_RENDER); + EXPECT_NE(nullptr, this->depsgraph); +} diff --git a/source/blender/blenloader/tests/blendfile_loading_base_test.cc b/source/blender/blenloader/tests/blendfile_loading_base_test.cc new file mode 100644 index 00000000000..d74bab4b31c --- /dev/null +++ b/source/blender/blenloader/tests/blendfile_loading_base_test.cc @@ -0,0 +1,162 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2019 by Blender Foundation. + */ +#include "blendfile_loading_base_test.h" + +#include "MEM_guardedalloc.h" + +#include "BKE_appdir.h" +#include "BKE_blender.h" +#include "BKE_context.h" +#include "BKE_global.h" +#include "BKE_idtype.h" +#include "BKE_image.h" +#include "BKE_main.h" +#include "BKE_modifier.h" +#include "BKE_node.h" +#include "BKE_scene.h" + +#include "BLI_path_util.h" +#include "BLI_threads.h" + +#include "BLO_readfile.h" + +#include "DEG_depsgraph.h" +#include "DEG_depsgraph_build.h" + +#include "DNA_genfile.h" /* for DNA_sdna_current_init() */ +#include "DNA_windowmanager_types.h" + +#include "IMB_imbuf.h" + +#include "RNA_define.h" + +#include "WM_api.h" +#include "wm.h" + +BlendfileLoadingBaseTest::~BlendfileLoadingBaseTest() +{ +} + +void BlendfileLoadingBaseTest::SetUpTestCase() +{ + testing::Test::SetUpTestCase(); + + /* Minimal code to make loading a blendfile and constructing a depsgraph not crash, copied from + * main() in creator.c. */ + BLI_threadapi_init(); + + DNA_sdna_current_init(); + BKE_blender_globals_init(); + + BKE_idtype_init(); + IMB_init(); + BKE_images_init(); + BKE_modifier_init(); + DEG_register_node_types(); + RNA_init(); + init_nodesystem(); + + G.background = true; + G.factory_startup = true; + + /* Allocate a dummy window manager. The real window manager will try and load Python scripts from + * the release directory, which it won't be able to find. */ + ASSERT_EQ(G.main->wm.first, nullptr); + G.main->wm.first = MEM_callocN(sizeof(wmWindowManager), __func__); +} + +void BlendfileLoadingBaseTest::TearDownTestCase() +{ + if (G.main->wm.first != nullptr) { + MEM_freeN(G.main->wm.first); + G.main->wm.first = nullptr; + } + + /* Copied from WM_exit_ex() in wm_init_exit.c, and cherry-picked those lines that match the + * allocation/initialization done in SetUpTestCase(). */ + BKE_blender_free(); + RNA_exit(); + + DEG_free_node_types(); + DNA_sdna_current_free(); + BLI_threadapi_exit(); + + BKE_blender_atexit(); + + BKE_tempdir_session_purge(); + + testing::Test::TearDownTestCase(); +} + +void BlendfileLoadingBaseTest::TearDown() +{ + depsgraph_free(); + blendfile_free(); + + testing::Test::TearDown(); +} + +bool BlendfileLoadingBaseTest::blendfile_load(const char *filepath) +{ + const std::string &test_assets_dir = blender::tests::flags_test_asset_dir(); + if (test_assets_dir.empty()) { + return false; + } + + char abspath[FILENAME_MAX]; + BLI_path_join(abspath, sizeof(abspath), test_assets_dir.c_str(), filepath, NULL); + + bfile = BLO_read_from_file(abspath, BLO_READ_SKIP_NONE, NULL /* reports */); + if (bfile == nullptr) { + ADD_FAILURE() << "Unable to load file '" << filepath << "' from test assets dir '" + << test_assets_dir << "'"; + return false; + } + return true; +} + +void BlendfileLoadingBaseTest::blendfile_free() +{ + if (bfile == nullptr) { + return; + } + + wmWindowManager *wm = static_cast<wmWindowManager *>(bfile->main->wm.first); + if (wm != nullptr) { + wm_close_and_free(NULL, wm); + } + BLO_blendfiledata_free(bfile); + bfile = nullptr; +} + +void BlendfileLoadingBaseTest::depsgraph_create(eEvaluationMode depsgraph_evaluation_mode) +{ + depsgraph = DEG_graph_new( + bfile->main, bfile->curscene, bfile->cur_view_layer, depsgraph_evaluation_mode); + DEG_graph_build_from_view_layer(depsgraph, bfile->main, bfile->curscene, bfile->cur_view_layer); + BKE_scene_graph_update_tagged(depsgraph, bfile->main); +} + +void BlendfileLoadingBaseTest::depsgraph_free() +{ + if (depsgraph == nullptr) { + return; + } + DEG_graph_free(depsgraph); + depsgraph = nullptr; +} diff --git a/source/blender/blenloader/tests/blendfile_loading_base_test.h b/source/blender/blenloader/tests/blendfile_loading_base_test.h new file mode 100644 index 00000000000..a5e75ef6df8 --- /dev/null +++ b/source/blender/blenloader/tests/blendfile_loading_base_test.h @@ -0,0 +1,64 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2019 by Blender Foundation. + */ +#ifndef __BLENDFILE_LOADING_BASE_TEST_H__ +#define __BLENDFILE_LOADING_BASE_TEST_H__ + +#include "DEG_depsgraph.h" +#include "testing/testing.h" + +struct BlendFileData; +struct Depsgraph; + +class BlendfileLoadingBaseTest : public testing::Test { + protected: + struct BlendFileData *bfile = nullptr; + struct Depsgraph *depsgraph = nullptr; + + public: + virtual ~BlendfileLoadingBaseTest(); + + /* Sets up Blender just enough to not crash on loading + * a blendfile and constructing a depsgraph. */ + static void SetUpTestCase(); + static void TearDownTestCase(); + + protected: + /* Frees the depsgraph & blendfile. */ + virtual void TearDown(); + + /* Loads a blend file from the lib/tests directory from SVN. + * Returns 'ok' flag (true=good, false=bad) and sets this->bfile. + * Fails the test if the file cannot be loaded (still returns though). + * Requires the CLI argument --test-asset-dir to point to ../../lib/tests. + * + * WARNING: only files saved with Blender 2.80+ can be loaded. Since Blender + * is only partially initialized (most importantly, without window manager), + * the space types are not registered, so any versioning code that handles + * those will SEGFAULT. + */ + bool blendfile_load(const char *filepath); + /* Free bfile if it is not nullptr. */ + void blendfile_free(); + + /* Create a depsgraph. Assumes a blend file has been loaded to this->bfile. */ + void depsgraph_create(eEvaluationMode depsgraph_evaluation_mode); + /* Free the depsgraph if it's not nullptr. */ + void depsgraph_free(); +}; + +#endif /* __BLENDFILE_LOADING_BASE_TEST_H__ */ |