Fix T53481: Linked scene crashes on load
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user