Fix T64775: crash loading Eevee files with DoF, after recent changes
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Fri, 17 May 2019 20:28:49 +0000 (22:28 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Fri, 17 May 2019 20:51:08 +0000 (22:51 +0200)
Version after lib linking due to following ID pointers.

source/blender/blenloader/intern/versioning_280.c

index 23e8aba..4d4dc22 100644 (file)
@@ -1084,6 +1084,32 @@ void do_versions_after_linking_280(Main *bmain)
       BKE_rigidbody_constraints_collection_validate(scene, rbw);
     }
   }
+
+  if (!MAIN_VERSION_ATLEAST(bmain, 280, 69)) {
+    /* Unify DOF settings (EEVEE part only) */
+    const int SCE_EEVEE_DOF_ENABLED = (1 << 7);
+    LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
+      if (STREQ(scene->r.engine, RE_engine_id_BLENDER_EEVEE)) {
+        if (scene->eevee.flag & SCE_EEVEE_DOF_ENABLED) {
+          Object *cam_ob = scene->camera;
+          if (cam_ob && cam_ob->type == OB_CAMERA) {
+            Camera *cam = cam_ob->data;
+            cam->dof.flag |= CAM_DOF_ENABLED;
+          }
+        }
+      }
+    }
+
+    LISTBASE_FOREACH (Camera *, camera, &bmain->cameras) {
+      camera->dof.focus_object = camera->dof_ob;
+      camera->dof.focus_distance = camera->dof_distance;
+      camera->dof.aperture_fstop = camera->gpu_dof.fstop;
+      camera->dof.aperture_rotation = camera->gpu_dof.rotation;
+      camera->dof.aperture_ratio = camera->gpu_dof.ratio;
+      camera->dof.aperture_blades = camera->gpu_dof.num_blades;
+      camera->dof_ob = NULL;
+    }
+  }
 }
 
 /* NOTE: This version patch is intended for versions < 2.52.2,
@@ -3423,31 +3449,5 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
         light->sun_angle = 2.0f * atanf(light->area_size);
       }
     }
-
-    /* Unify DOF settings (EEVEE part only) */
-    if (!DNA_struct_elem_find(fd->filesdna, "Camera", "CameraDOFSettings", "dof")) {
-      const int SCE_EEVEE_DOF_ENABLED = (1 << 7);
-      LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
-        if (STREQ(scene->r.engine, RE_engine_id_BLENDER_EEVEE)) {
-          if (scene->eevee.flag & SCE_EEVEE_DOF_ENABLED) {
-            Object *cam_ob = scene->camera;
-            if (cam_ob && cam_ob->type == OB_CAMERA) {
-              Camera *cam = cam_ob->data;
-              cam->dof.flag |= CAM_DOF_ENABLED;
-            }
-          }
-        }
-      }
-
-      LISTBASE_FOREACH (Camera *, camera, &bmain->cameras) {
-        camera->dof.focus_object = camera->dof_ob;
-        camera->dof.focus_distance = camera->dof_distance;
-        camera->dof.aperture_fstop = camera->gpu_dof.fstop;
-        camera->dof.aperture_rotation = camera->gpu_dof.rotation;
-        camera->dof.aperture_ratio = camera->gpu_dof.ratio;
-        camera->dof.aperture_blades = camera->gpu_dof.num_blades;
-        camera->dof_ob = NULL;
-      }
-    }
   }
 }