From 8a812e334d07fa8be186bc66f5a14a9ba86e702d Mon Sep 17 00:00:00 2001 From: Sean Kim Date: Fri, 26 Jul 2024 18:01:11 +0200 Subject: [PATCH] Fix #125375: Sculpt undo with duplicate object causes crash Introduced with d527e3a6bd787c2f58837c6f93ccd7d8b466c779. 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 --- source/blender/blenkernel/intern/pbvh.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/source/blender/blenkernel/intern/pbvh.cc b/source/blender/blenkernel/intern/pbvh.cc index ba811067cbf..186ce741046 100644 --- a/source/blender/blenkernel/intern/pbvh.cc +++ b/source/blender/blenkernel/intern/pbvh.cc @@ -1010,6 +1010,19 @@ static void update_normals_faces(Tree &pbvh, Span 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 boundary_verts; threading::parallel_invoke( [&]() {