Fix T70965: Undo crash with specific file
authorJulian Eisel <eiseljulian@gmail.com>
Wed, 15 Jan 2020 16:46:50 +0000 (17:46 +0100)
committerJulian Eisel <eiseljulian@gmail.com>
Wed, 15 Jan 2020 16:48:45 +0000 (17:48 +0100)
Not sure how the WorkSpaceLayout.screen pointer could end up being NULL,
but apparently that happens, or at least happened with older files.

Rather than just adding NULL-checks, prefer not keeping around those
invalid layouts at all.

source/blender/blenkernel/intern/workspace.c
source/blender/blenloader/intern/readfile.c

index 3e449fa6b2508bee511ac71aa75c09e077b87377..f58c20a7d7238dc2f874924e4f442e8d61562fa5 100644 (file)
@@ -247,8 +247,12 @@ WorkSpaceLayout *BKE_workspace_layout_add(Main *bmain,
 
 void BKE_workspace_layout_remove(Main *bmain, WorkSpace *workspace, WorkSpaceLayout *layout)
 {
-  id_us_min(&layout->screen->id);
-  BKE_id_free(bmain, layout->screen);
+  /* Screen should usually be set, but we call this from file reading to get rid of invalid
+   * layouts. */
+  if (layout->screen) {
+    id_us_min(&layout->screen->id);
+    BKE_id_free(bmain, layout->screen);
+  }
   BLI_freelinkN(&workspace->layouts, layout);
 }
 
index 086f1db117d65a9f510d2725b5bbde66dd3f48a3..fbe270dd0608524b70fe2a543d0692f820a23a70 100644 (file)
@@ -3377,6 +3377,11 @@ static void lib_link_workspaces(FileData *fd, Main *bmain)
           }
         }
       }
+      else {
+        /* If we're reading a layout without screen stored, it's useless and we shouldn't keep it
+         * around. */
+        BKE_workspace_layout_remove(bmain, workspace, layout);
+      }
     }
 
     id->tag &= ~LIB_TAG_NEED_LINK;