From 6987060f7082e77cfc4ead7db3e7c9d6aaf349b1 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Tue, 23 Nov 2021 09:32:12 +0100 Subject: Fix T93090: crash with data transfer modifier and geometry nodes There was a missing normals layer that was requested by the data transfer modifier from the target object. The normal layer was correctly added to the target object. However, it never reached the data transfer modifier because the mesh was copied in `BKE_object_get_evaluated_mesh` (in the call to `get_mesh_for_write`) and the copy does not include the normals layer. The solution is to not use `get_mesh_for_write` here which was only used because `BKE_object_get_evaluated_mesh` returns a non-const `Mesh *`. Mid term, it should actually return a `const Mesh *` to avoid the confusion. Differential Revision: https://developer.blender.org/D13319 --- source/blender/blenkernel/intern/object.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/object.cc b/source/blender/blenkernel/intern/object.cc index deef053b658..4b01ee29828 100644 --- a/source/blender/blenkernel/intern/object.cc +++ b/source/blender/blenkernel/intern/object.cc @@ -4564,10 +4564,11 @@ Mesh *BKE_object_get_evaluated_mesh(const Object *object) * object types either store it there or add a reference to it if it's owned elsewhere. */ GeometrySet *geometry_set_eval = object->runtime.geometry_set_eval; if (geometry_set_eval) { - /* Some areas expect to be able to modify the evaluated mesh. Theoretically this should be - * avoided, or at least protected with a lock, so a const mesh could be returned from this - * function. */ - Mesh *mesh = geometry_set_eval->get_mesh_for_write(); + /* Some areas expect to be able to modify the evaluated mesh in limited ways. Theoretically + * this should be avoided, or at least protected with a lock, so a const mesh could be returned + * from this function. We use a const_cast instead of #get_mesh_for_write, because that might + * result in a copy of the mesh when it is shared. */ + Mesh *mesh = const_cast(geometry_set_eval->get_mesh_for_read()); if (mesh) { return mesh; } -- cgit v1.2.3