Commit: d59b74adb38f3ac6b85107aa506e471efbd2a20c
Author: Campbell Barton
Date:   Wed May 23 12:19:56 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBd59b74adb38f3ac6b85107aa506e471efbd2a20c

Fix T53481: Linked scene crashes on load

===================================================================

M       source/blender/blenloader/intern/readfile.c
M       source/blender/blenloader/intern/writefile.c
M       source/blender/makesdna/DNA_workspace_types.h

===================================================================

diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index 867eb1d749a..6695b6ced37 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2882,7 +2882,15 @@ static void lib_link_workspaces(FileData *fd, Main 
*bmain)
                     relation = relation->next)
                {
                        relation->parent = newlibadr(fd, id->lib, 
relation->parent);
-                       /* relation->value is set in 
direct_link_workspace_link_scene_data */
+                       /* relation->value is set in 
direct_link_workspace_link_scene_data,
+                        * except when loading linked data. */
+                       Scene *scene = relation->parent;
+                       if (scene->id.lib != NULL) {
+                               relation->value = 
BLI_findstring(&scene->view_layers, relation->value_idname, offsetof(ViewLayer, 
name));
+                       }
+                       if (relation->value == NULL) {
+                               relation->value = scene->view_layers.first;
+                       }
                }
 
                for (WorkSpaceLayout *layout = layouts->first, *layout_next; 
layout; layout = layout_next) {
@@ -6066,12 +6074,15 @@ static void direct_link_workspace_link_scene_data(
                     relation != NULL;
                     relation = relation->next)
                {
-                       ViewLayer *layer = newdataadr(fd, relation->value);
-                       if (layer) {
-                               BLI_assert(BLI_findindex(&scene->view_layers, 
layer) != -1);
+                       ViewLayer *view_layer = newdataadr(fd, relation->value);
+                       if (view_layer != NULL) {
+                               BLI_assert(BLI_findindex(&scene->view_layers, 
view_layer) != -1);
                                /* relation->parent is set in 
lib_link_workspaces */
-                               relation->value = layer;
                        }
+                       if (UNLIKELY(view_layer == NULL)) {
+                               view_layer = scene->view_layers.first;
+                       }
+                       relation->value = view_layer;
                }
        }
 }
diff --git a/source/blender/blenloader/intern/writefile.c 
b/source/blender/blenloader/intern/writefile.c
index a3cac39f609..a1789ac3d5d 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -3596,6 +3596,14 @@ static void write_workspace(WriteData *wd, WorkSpace 
*workspace)
 {
        ListBase *layouts = BKE_workspace_layouts_get(workspace);
 
+       /* Update the names for file (only need to set on write). */
+       for (WorkSpaceDataRelation *relation = 
workspace->scene_viewlayer_relations.first;
+            relation;
+            relation = relation->next)
+       {
+               STRNCPY(relation->value_idname, ((ViewLayer 
*)relation->value)->name);
+       }
+
        writestruct(wd, ID_WS, WorkSpace, 1, workspace);
        writelist(wd, DATA, WorkSpaceLayout, layouts);
        writelist(wd, DATA, WorkSpaceDataRelation, 
&workspace->hook_layout_relations);
diff --git a/source/blender/makesdna/DNA_workspace_types.h 
b/source/blender/makesdna/DNA_workspace_types.h
index 9da42d71d0f..784e563486f 100644
--- a/source/blender/makesdna/DNA_workspace_types.h
+++ b/source/blender/makesdna/DNA_workspace_types.h
@@ -180,6 +180,9 @@ typedef struct WorkSpaceDataRelation {
        void *parent;
        /* The value for this parent-data/workspace relation */
        void *value;
+
+       /** Use when we reference non-ID data, this allows use to look it up 
when linking in a workspace. */
+       char value_idname[64];  /* MAX_NAME. */
 } WorkSpaceDataRelation;
 
 #endif /* DNA_PRIVATE_WORKSPACE_READ_WRITE */

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to