Commit: b4051db4fc3ae509aa65f96af348f8241ceb726f
Author: Philipp Oeser
Date:   Wed Aug 14 10:48:25 2019 +0200
Branches: master
https://developer.blender.org/rBb4051db4fc3ae509aa65f96af348f8241ceb726f

Fix cycles crash when voxel attributes changed

This could happen e.g. when changing smoke type from flow to domain or
connecting a volume shader with to a domain without an actual flow type
around.

Fixes T58569, T68359

Reviewers: brecht

Maniphest Tasks: T58569, T68359

Differential Revision: https://developer.blender.org/D5478

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

M       intern/cycles/blender/blender_mesh.cpp
M       intern/cycles/render/mesh.cpp
M       intern/cycles/render/mesh.h

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

diff --git a/intern/cycles/blender/blender_mesh.cpp 
b/intern/cycles/blender/blender_mesh.cpp
index c672bc9f3e2..551866f7fce 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -1002,6 +1002,9 @@ Mesh *BlenderSync::sync_mesh(BL::Depsgraph &b_depsgraph,
   oldcurve_keys.steal_data(mesh->curve_keys);
   oldcurve_radius.steal_data(mesh->curve_radius);
 
+  /* ensure bvh rebuild (instead of refit) if has_voxel_attributes() changed */
+  bool oldhas_voxel_attributes = mesh->has_voxel_attributes();
+
   mesh->clear();
   mesh->used_shaders = used_shaders;
   mesh->name = ustring(b_ob_data.name().c_str());
@@ -1050,7 +1053,8 @@ Mesh *BlenderSync::sync_mesh(BL::Depsgraph &b_depsgraph,
   /* tag update */
   bool rebuild = (oldtriangles != mesh->triangles) || (oldsubd_faces != 
mesh->subd_faces) ||
                  (oldsubd_face_corners != mesh->subd_face_corners) ||
-                 (oldcurve_keys != mesh->curve_keys) || (oldcurve_radius != 
mesh->curve_radius);
+                 (oldcurve_keys != mesh->curve_keys) || (oldcurve_radius != 
mesh->curve_radius) ||
+                 (oldhas_voxel_attributes != mesh->has_voxel_attributes());
 
   mesh->tag_update(scene, rebuild);
 
diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp
index 91c3a772537..6ac66661859 100644
--- a/intern/cycles/render/mesh.cpp
+++ b/intern/cycles/render/mesh.cpp
@@ -1091,6 +1091,17 @@ bool Mesh::has_true_displacement() const
   return false;
 }
 
+bool Mesh::has_voxel_attributes() const
+{
+  foreach (const Attribute &attr, attributes.attributes) {
+    if (attr.element == ATTR_ELEMENT_VOXEL) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
 float Mesh::motion_time(int step) const
 {
   return (motion_steps > 1) ? 2.0f * step / (motion_steps - 1) - 1.0f : 0.0f;
@@ -2020,15 +2031,7 @@ void MeshManager::device_update_preprocess(Device 
*device, Scene *scene, Progres
 
     if (need_update && mesh->has_volume) {
       /* Create volume meshes if there is voxel data. */
-      bool has_voxel_attributes = false;
-
-      foreach (Attribute &attr, mesh->attributes.attributes) {
-        if (attr.element == ATTR_ELEMENT_VOXEL) {
-          has_voxel_attributes = true;
-        }
-      }
-
-      if (has_voxel_attributes) {
+      if (mesh->has_voxel_attributes()) {
         if (!volume_images_updated) {
           progress.set_status("Updating Meshes Volume Bounds");
           device_update_volume_images(device, scene, progress);
diff --git a/intern/cycles/render/mesh.h b/intern/cycles/render/mesh.h
index 05c67ccb3b7..5bb6ab328b7 100644
--- a/intern/cycles/render/mesh.h
+++ b/intern/cycles/render/mesh.h
@@ -318,6 +318,7 @@ class Mesh : public Node {
 
   bool has_motion_blur() const;
   bool has_true_displacement() const;
+  bool has_voxel_attributes() const;
 
   /* Convert between normalized -1..1 motion time and index
    * in the VERTEX_MOTION attribute. */

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to