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.

---

Original PR: https://projects.blender.org/blender/blender/pulls/125396

Pull Request: https://projects.blender.org/blender/blender/pulls/126020
This commit is contained in:
Sean Kim
2024-08-07 11:15:56 +02:00
committed by Philipp Oeser
parent 3bfa5a0f70
commit 025735cef7
+13
View File
@@ -1177,6 +1177,19 @@ static void update_normals_faces(PBVH &pbvh, Span<PBVHNode *> 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(
[&]() {