Fix T82852: Cycles crashes when editing a mesh with adaptive subdivision
The issue is caused by stale data on the Mesh Node which is not cleared during synchronizing since the socket API refactor so that we can detect changes. However, synchronization only updates the sockets of the Mesh, so other properties were left with outdated values. This caused an underflow when computing attribute size for undisplaced coordinates as it was using the current number of vertices minus the previous count of subdivision vertices, which at this point should be 0. Added a simple method to clear non socket data. Also modified Mesh.add_undisplaced to always use an ATTR_PRIM_GEOMETRY as the data is not subdivided yet and it avoids any further issues regarding computing attribute sizes.
This commit is contained in:
@@ -1064,6 +1064,8 @@ void BlenderSync::sync_mesh(BL::Depsgraph b_depsgraph, BL::Object b_ob, Mesh *me
|
||||
|
||||
/* update original sockets */
|
||||
|
||||
mesh->clear_non_sockets();
|
||||
|
||||
for (const SocketType &socket : new_mesh.type->inputs) {
|
||||
/* Those sockets are updated in sync_object, so do not modify them. */
|
||||
if (socket.name == "use_motion_blur" || socket.name == "motion_steps" ||
|
||||
|
@@ -277,6 +277,20 @@ void Mesh::reserve_subd_creases(size_t num_creases)
|
||||
subd_creases_weight.reserve(num_creases);
|
||||
}
|
||||
|
||||
void Mesh::clear_non_sockets()
|
||||
{
|
||||
Geometry::clear(true);
|
||||
|
||||
num_subd_verts = 0;
|
||||
num_subd_faces = 0;
|
||||
|
||||
vert_to_stitching_key_map.clear();
|
||||
vert_stitching_map.clear();
|
||||
|
||||
delete patch_table;
|
||||
patch_table = NULL;
|
||||
}
|
||||
|
||||
void Mesh::clear(bool preserve_shaders, bool preserve_voxel_data)
|
||||
{
|
||||
Geometry::clear(preserve_shaders);
|
||||
@@ -297,22 +311,15 @@ void Mesh::clear(bool preserve_shaders, bool preserve_voxel_data)
|
||||
subd_ptex_offset.clear();
|
||||
subd_face_corners.clear();
|
||||
|
||||
num_subd_verts = 0;
|
||||
num_subd_faces = 0;
|
||||
|
||||
subd_creases_edge.clear();
|
||||
subd_creases_weight.clear();
|
||||
|
||||
subd_attributes.clear();
|
||||
attributes.clear(preserve_voxel_data);
|
||||
|
||||
vert_to_stitching_key_map.clear();
|
||||
vert_stitching_map.clear();
|
||||
|
||||
subdivision_type = SubdivisionType::SUBDIVISION_NONE;
|
||||
|
||||
delete patch_table;
|
||||
patch_table = NULL;
|
||||
clear_non_sockets();
|
||||
}
|
||||
|
||||
void Mesh::clear(bool preserve_shaders)
|
||||
@@ -662,7 +669,7 @@ void Mesh::add_undisplaced()
|
||||
float3 *data = attr->data_float3();
|
||||
|
||||
/* copy verts */
|
||||
size_t size = attr->buffer_size(this, attrs.prim);
|
||||
size_t size = attr->buffer_size(this, ATTR_PRIM_GEOMETRY);
|
||||
|
||||
/* Center points for ngons aren't stored in Mesh::verts but are included in size since they will
|
||||
* be calculated later, we subtract them from size here so we don't have an overflow while
|
||||
|
@@ -205,6 +205,7 @@ class Mesh : public Geometry {
|
||||
void resize_subd_faces(int numfaces, int num_ngons, int numcorners);
|
||||
void reserve_subd_faces(int numfaces, int num_ngons, int numcorners);
|
||||
void reserve_subd_creases(size_t num_creases);
|
||||
void clear_non_sockets();
|
||||
void clear(bool preserve_shaders = false) override;
|
||||
void add_vertex(float3 P);
|
||||
void add_vertex_slow(float3 P);
|
||||
|
Reference in New Issue
Block a user