diff options
Diffstat (limited to 'source/blender/blenloader/intern/readfile.c')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 1072cd3686e..aa2f103c693 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -1794,7 +1794,7 @@ static void *newdataadr_no_us(FileData *fd, const void *adr) } /* direct datablocks with global linking */ -static void *newglobadr(FileData *fd, const void *adr) +void *blo_read_get_new_globaldata_address(FileData *fd, const void *adr) { return oldnewmap_lookup_and_inc(fd->globmap, adr, true); } @@ -2553,6 +2553,21 @@ static void lib_link_workspaces(BlendLibReader *reader, WorkSpace *workspace) { ID *id = (ID *)workspace; + /* Restore proper 'parent' pointers to relevant data, and clean up unused/invalid entries. */ + LISTBASE_FOREACH_MUTABLE (WorkSpaceDataRelation *, relation, &workspace->hook_layout_relations) { + relation->parent = NULL; + LISTBASE_FOREACH (wmWindowManager *, wm, &reader->main->wm) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { + if (win->winid == relation->parentid) { + relation->parent = win->workspace_hook; + } + } + } + if (relation->parent == NULL) { + BLI_freelinkN(&workspace->hook_layout_relations, relation); + } + } + LISTBASE_FOREACH_MUTABLE (WorkSpaceLayout *, layout, &workspace->layouts) { BLO_read_id_address(reader, id->lib, &layout->screen); @@ -2581,12 +2596,8 @@ static void direct_link_workspace(BlendDataReader *reader, WorkSpace *workspace) BLO_read_list(reader, &workspace->tools); LISTBASE_FOREACH (WorkSpaceDataRelation *, relation, &workspace->hook_layout_relations) { - /* data from window - need to access through global oldnew-map */ - /* XXX This is absolutely not acceptable. There is no acceptable reasons to mess with other - * ID's data in read code, and certainly never, ever in `direct_link_` functions. - * Kept for now because it seems to work, but it should be refactored. Probably store and use - * window's `winid`, just like it was already done for screens? */ - relation->parent = newglobadr(reader->fd, relation->parent); + /* parent pointer does not belong to workspace data and is therefore restored in lib_link step + * of window manager.*/ BLO_read_data_address(reader, &relation->value); } @@ -5472,8 +5483,9 @@ static void direct_link_windowmanager(BlendDataReader *reader, wmWindowManager * WorkSpaceInstanceHook *hook = win->workspace_hook; BLO_read_data_address(reader, &win->workspace_hook); - /* we need to restore a pointer to this later when reading workspaces, - * so store in global oldnew-map. */ + /* We need to restore a pointer to this later when reading workspaces, + * so store in global oldnew-map. + * Note that this is only needed for versionning of older .blend files now.. */ oldnewmap_insert(reader->fd->globmap, hook, win->workspace_hook, 0); direct_link_area_map(reader, &win->global_areas); @@ -6847,7 +6859,7 @@ static BHead *read_global(BlendFileData *bfd, FileData *fd, BHead *bhead) /* note, this has to be kept for reading older files... */ static void link_global(FileData *fd, BlendFileData *bfd) { - bfd->cur_view_layer = newglobadr(fd, bfd->cur_view_layer); + bfd->cur_view_layer = blo_read_get_new_globaldata_address(fd, bfd->cur_view_layer); bfd->curscreen = newlibadr(fd, NULL, bfd->curscreen); bfd->curscene = newlibadr(fd, NULL, bfd->curscene); // this happens in files older than 2.35 |