Make libquery resilient to old blend-files missing pointers.
authorBastien Montagne <b.mont29@gmail.com>
Fri, 14 Feb 2020 11:50:52 +0000 (12:50 +0100)
committerBastien Montagne <b.mont29@gmail.com>
Fri, 14 Feb 2020 11:52:47 +0000 (12:52 +0100)
This makes libquery usable during blendfile reading phases.

Some pointers that shall never be NULL in modern Main database did not
exist before.

source/blender/blenkernel/intern/lib_query.c

index fcbb1458749c96d6594ec837751dcc1fa50ed2b8..4b4d744c41add82eb3f507b2143542247048956f 100644 (file)
@@ -528,7 +528,10 @@ static void library_foreach_ID_link(Main *bmain,
           SEQ_END;
         }
 
-        library_foreach_collection(&data, scene->master_collection);
+        /* This pointer can be NULL during old files reading, better be safe than sorry. */
+        if (scene->master_collection != NULL) {
+          library_foreach_collection(&data, scene->master_collection);
+        }
 
         ViewLayer *view_layer;
         for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
@@ -1030,13 +1033,15 @@ static void library_foreach_ID_link(Main *bmain,
         wmWindowManager *wm = (wmWindowManager *)id;
 
         for (wmWindow *win = wm->windows.first; win; win = win->next) {
-          ID *workspace = (ID *)BKE_workspace_active_get(win->workspace_hook);
-
           CALLBACK_INVOKE(win->scene, IDWALK_CB_USER_ONE);
 
-          CALLBACK_INVOKE_ID(workspace, IDWALK_CB_NOP);
-          /* allow callback to set a different workspace */
-          BKE_workspace_active_set(win->workspace_hook, (WorkSpace *)workspace);
+          /* This pointer can be NULL during old files reading, better be safe than sorry. */
+          if (win->workspace_hook != NULL) {
+            ID *workspace = (ID *)BKE_workspace_active_get(win->workspace_hook);
+            CALLBACK_INVOKE_ID(workspace, IDWALK_CB_NOP);
+            /* allow callback to set a different workspace */
+            BKE_workspace_active_set(win->workspace_hook, (WorkSpace *)workspace);
+          }
         }
         break;
       }