[Bf-blender-cvs] [8730984c708] master: Fix (unreported) datatransfer code could still modify source mesh in some cases.

Bastien Montagne noreply at git.blender.org
Fri Mar 8 17:53:49 CET 2019


Commit: 8730984c708bdde6a2cf29fc4f29bd50c05b349c
Author: Bastien Montagne
Date:   Fri Mar 8 11:49:49 2019 +0100
Branches: master
https://developer.blender.org/rB8730984c708bdde6a2cf29fc4f29bd50c05b349c

Fix (unreported) datatransfer code could still modify source mesh in some cases.

Source (i.e. other) mesh should not be modified in any case in modifier
evaluation case (this is forbidden by design and can lead to all kind of
threaded locks and crashes), and doing so even in operator case was
never a good idea either.

Now that we can specifically request needed data (poly and/or loop
normals) from evaluation code, we can finally get rid of those
computations inside data transfer/mesh remapping area.

This is hopefully the last remaining bit of this 'bad crashing code' in
datatransfer area.

===================================================================

M	source/blender/blenkernel/intern/data_transfer.c
M	source/blender/blenkernel/intern/mesh_remap.c
M	source/blender/modifiers/intern/MOD_datatransfer.c

===================================================================

diff --git a/source/blender/blenkernel/intern/data_transfer.c b/source/blender/blenkernel/intern/data_transfer.c
index 4c4d57ddbac..cf6a5a7233a 100644
--- a/source/blender/blenkernel/intern/data_transfer.c
+++ b/source/blender/blenkernel/intern/data_transfer.c
@@ -257,7 +257,7 @@ int BKE_object_data_transfer_dttype_to_srcdst_index(const int dtdata_type)
 
 static void data_transfer_dtdata_type_preprocess(
         Mesh *me_src, Mesh *me_dst,
-        const int dtdata_type, const bool dirty_nors_dst, const bool is_modifier)
+        const int dtdata_type, const bool dirty_nors_dst)
 {
 	if (dtdata_type == DT_TYPE_LNOR) {
 		/* Compute custom normals into regular loop normals, which will be used for the transfer. */
@@ -275,9 +275,9 @@ static void data_transfer_dtdata_type_preprocess(
 		const bool use_split_nors_dst = (me_dst->flag & ME_AUTOSMOOTH) != 0;
 		const float split_angle_dst = me_dst->smoothresh;
 
-		if (!is_modifier) {
-			BKE_mesh_calc_normals_split(me_src);
-		}
+		/* This should be ensured by cddata_masks we pass to code generating/giving us me_src now. */
+		BLI_assert(CustomData_get_layer(&me_src->ldata, CD_NORMAL) != NULL);
+		BLI_assert(CustomData_get_layer(&me_src->pdata, CD_NORMAL) != NULL);
 
 		float (*poly_nors_dst)[3];
 		float (*loop_nors_dst)[3];
@@ -1121,6 +1121,8 @@ bool BKE_object_data_transfer_ex(
 
 	/* Get source evaluated mesh.*/
 	BKE_object_data_transfer_dttypes_to_cdmask(data_types, &me_src_mask);
+	BKE_mesh_remap_calc_source_cddata_masks_from_map_modes(
+	            map_vert_mode, map_edge_mode, map_loop_mode, map_poly_mode, &me_src_mask);
 	if (is_modifier) {
 		me_src = BKE_modifier_get_evaluated_mesh_from_evaluated_object(ob_src, false);
 
@@ -1155,7 +1157,7 @@ bool BKE_object_data_transfer_ex(
 			continue;
 		}
 
-		data_transfer_dtdata_type_preprocess(me_src, me_dst, dtdata_type, dirty_nors_dst, is_modifier);
+		data_transfer_dtdata_type_preprocess(me_src, me_dst, dtdata_type, dirty_nors_dst);
 
 		cddata_type = BKE_object_data_transfer_dttype_to_cdtype(dtdata_type);
 
diff --git a/source/blender/blenkernel/intern/mesh_remap.c b/source/blender/blenkernel/intern/mesh_remap.c
index 55e8a96fa16..7219332774a 100644
--- a/source/blender/blenkernel/intern/mesh_remap.c
+++ b/source/blender/blenkernel/intern/mesh_remap.c
@@ -1251,18 +1251,13 @@ void BKE_mesh_remap_calc_loops_from_mesh(
 				}
 			}
 			if (need_pnors_src || need_lnors_src) {
-				/* Simpler for now, calcNormals never stores pnors :( */
-				if (!CustomData_has_layer(&me_src->pdata, CD_NORMAL)) {
-					CustomData_add_layer(&me_src->pdata, CD_NORMAL, CD_CALLOC, NULL, me_src->totpoly);
-					CustomData_set_layer_flag(&me_src->pdata, CD_NORMAL, CD_FLAG_TEMPORARY);
-				}
-				BKE_mesh_calc_normals_split(me_src);
-
 				if (need_pnors_src) {
 					poly_nors_src = CustomData_get_layer(&me_src->pdata, CD_NORMAL);
+					BLI_assert(poly_nors_src != NULL);
 				}
 				if (need_lnors_src) {
 					loop_nors_src = CustomData_get_layer(&me_src->ldata, CD_NORMAL);
+					BLI_assert(loop_nors_src != NULL);
 				}
 			}
 		}
diff --git a/source/blender/modifiers/intern/MOD_datatransfer.c b/source/blender/modifiers/intern/MOD_datatransfer.c
index 3e461476eac..1371dd947bb 100644
--- a/source/blender/modifiers/intern/MOD_datatransfer.c
+++ b/source/blender/modifiers/intern/MOD_datatransfer.c
@@ -85,6 +85,8 @@ static void requiredDataMask(Object *UNUSED(ob), ModifierData *md, CustomData_Me
 	}
 
 	BKE_object_data_transfer_dttypes_to_cdmask(dtmd->data_types, r_cddata_masks);
+	BKE_mesh_remap_calc_source_cddata_masks_from_map_modes(
+	            dtmd->vmap_mode, dtmd->emap_mode, dtmd->lmap_mode, dtmd->pmap_mode, r_cddata_masks);
 }
 
 static bool dependsOnNormals(ModifierData *md)



More information about the Bf-blender-cvs mailing list