Fix #125375: Sculpt undo with duplicate object causes crash

Introduced with d527e3a6bd.

Cached values are tagged as dirty during the update step, this can cause
conflicts where we attempt to then flush then changes into the PBVH but
have not yet updated the mesh pointers and reinitialized them.

This commit forcibly initializes the underlying data to prevent such
cases from happening when flushing to the PBVH.

Pull Request: https://projects.blender.org/blender/blender/pulls/125396
This commit is contained in:
Sean Kim
2024-07-26 18:01:11 +02:00
committed by Sean Kim
parent 13795b5df1
commit 8a812e334d

View File

@@ -1010,6 +1010,19 @@ static void update_normals_faces(Tree &pbvh, Span<Node *> nodes, Mesh &mesh)
}
}
/* In certain cases when undoing strokes on a duplicate object, the cached data may be marked
* dirty before this code is run, leaving the relevant vectors empty. We force reinitialize the
* vectors to prevent crashes here.
* See #125375 for more detail. */
if (!pbvh.deformed_) {
if (mesh.runtime->face_normals_cache.is_dirty()) {
mesh.face_normals();
}
if (mesh.runtime->vert_normals_cache.is_dirty()) {
mesh.vert_normals();
}
}
VectorSet<int> boundary_verts;
threading::parallel_invoke(
[&]() {