From bb24677a76ce5af97ca09fb05fb0d53b66a13993 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 26 Aug 2024 19:11:02 +0200 Subject: [PATCH] Cleanup: Rename `CustomData_copy` to `CustomData_initi_from`. And same for the `copy_layout` function. These functions do not free any potentially existing data in destination, but expect it to be uninitialized. Hopefully these new names will make it more clear and avoid bugs like #122160. --- source/blender/blenkernel/BKE_customdata.hh | 18 ++++---- .../blenkernel/intern/curves_geometry.cc | 4 +- .../blender/blenkernel/intern/curves_utils.cc | 2 +- .../blender/blenkernel/intern/customdata.cc | 15 ++++--- .../blenkernel/intern/grease_pencil.cc | 20 ++++----- source/blender/blenkernel/intern/instances.cc | 2 +- source/blender/blenkernel/intern/mesh.cc | 23 +++++----- .../blender/blenkernel/intern/mesh_convert.cc | 11 +++-- .../blenkernel/intern/mesh_legacy_convert.cc | 2 +- .../intern/mesh_legacy_derived_mesh.cc | 14 +++--- .../blender/blenkernel/intern/pointcloud.cc | 4 +- .../blender/blenkernel/intern/subdiv_mesh.cc | 44 +++++++++---------- .../blender/bmesh/intern/bmesh_construct.cc | 24 ++++++---- .../bmesh/intern/bmesh_mesh_convert.cc | 24 +++++----- .../intern/grease_pencil_undo.cc | 4 +- source/blender/editors/mesh/mesh_data.cc | 9 ++-- .../editors/sculpt_paint/sculpt_undo.cc | 22 ++++++---- source/blender/geometry/intern/randomize.cc | 4 +- source/blender/io/collada/MeshImporter.cpp | 2 +- 19 files changed, 138 insertions(+), 110 deletions(-) diff --git a/source/blender/blenkernel/BKE_customdata.hh b/source/blender/blenkernel/BKE_customdata.hh index 2a462b95d82..f62c9301759 100644 --- a/source/blender/blenkernel/BKE_customdata.hh +++ b/source/blender/blenkernel/BKE_customdata.hh @@ -162,10 +162,10 @@ void CustomData_data_add(eCustomDataType type, void *data1, const void *data2); * \warning Does not free or release any internal resources in `dest` CustomData, code must call * #CustomData_free first if needed. */ -void CustomData_copy(const CustomData *source, - CustomData *dest, - eCustomDataMask mask, - int totelem); +void CustomData_init_from(const CustomData *source, + CustomData *dest, + eCustomDataMask mask, + int totelem); /** * Initializes a CustomData object with the same layers as source. The data is not copied from the * source. Instead, the new layers are initialized using the given `alloctype`. @@ -173,11 +173,11 @@ void CustomData_copy(const CustomData *source, * \warning Does not free or release any internal resources in `dest` CustomData, code must call * #CustomData_free first if needed. */ -void CustomData_copy_layout(const CustomData *source, - CustomData *dest, - eCustomDataMask mask, - eCDAllocType alloctype, - int totelem); +void CustomData_init_layout_from(const CustomData *source, + CustomData *dest, + eCustomDataMask mask, + eCDAllocType alloctype, + int totelem); /* BMESH_TODO, not really a public function but `readfile.cc` needs it. */ void CustomData_update_typemap(CustomData *data); diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc index eea33e11dc3..a82be367318 100644 --- a/source/blender/blenkernel/intern/curves_geometry.cc +++ b/source/blender/blenkernel/intern/curves_geometry.cc @@ -97,8 +97,8 @@ CurvesGeometry::CurvesGeometry(const CurvesGeometry &other) other.runtime->curve_offsets_sharing_info->add_user(); } - CustomData_copy(&other.point_data, &this->point_data, CD_MASK_ALL, other.point_num); - CustomData_copy(&other.curve_data, &this->curve_data, CD_MASK_ALL, other.curve_num); + CustomData_init_from(&other.point_data, &this->point_data, CD_MASK_ALL, other.point_num); + CustomData_init_from(&other.curve_data, &this->curve_data, CD_MASK_ALL, other.curve_num); this->point_num = other.point_num; this->curve_num = other.curve_num; diff --git a/source/blender/blenkernel/intern/curves_utils.cc b/source/blender/blenkernel/intern/curves_utils.cc index b83a2a97bdb..8ffe259457f 100644 --- a/source/blender/blenkernel/intern/curves_utils.cc +++ b/source/blender/blenkernel/intern/curves_utils.cc @@ -27,7 +27,7 @@ void fill_points(const OffsetIndices points_by_curve, CurvesGeometry copy_only_curve_domain(const CurvesGeometry &src_curves) { CurvesGeometry dst_curves(0, src_curves.curves_num()); - CustomData_copy( + CustomData_init_from( &src_curves.curve_data, &dst_curves.curve_data, CD_MASK_ALL, src_curves.curves_num()); dst_curves.runtime->type_counts = src_curves.runtime->type_counts; return dst_curves; diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc index 036242a9942..95ecd1b5816 100644 --- a/source/blender/blenkernel/intern/customdata.cc +++ b/source/blender/blenkernel/intern/customdata.cc @@ -2687,7 +2687,10 @@ void CustomData_realloc(CustomData *data, } } -void CustomData_copy(const CustomData *source, CustomData *dest, eCustomDataMask mask, int totelem) +void CustomData_init_from(const CustomData *source, + CustomData *dest, + eCustomDataMask mask, + int totelem) { CustomData_reset(dest); @@ -2698,11 +2701,11 @@ void CustomData_copy(const CustomData *source, CustomData *dest, eCustomDataMask CustomData_merge(source, dest, mask, totelem); } -void CustomData_copy_layout(const CustomData *source, - CustomData *dest, - eCustomDataMask mask, - eCDAllocType alloctype, - int totelem) +void CustomData_init_layout_from(const CustomData *source, + CustomData *dest, + eCustomDataMask mask, + eCDAllocType alloctype, + int totelem) { CustomData_reset(dest); diff --git a/source/blender/blenkernel/intern/grease_pencil.cc b/source/blender/blenkernel/intern/grease_pencil.cc index f618dbff8b7..35ef502dfe2 100644 --- a/source/blender/blenkernel/intern/grease_pencil.cc +++ b/source/blender/blenkernel/intern/grease_pencil.cc @@ -127,10 +127,10 @@ static void grease_pencil_copy_data(Main * /*bmain*/, grease_pencil_dst->set_active_node(active_node); } - CustomData_copy(&grease_pencil_src->layers_data, - &grease_pencil_dst->layers_data, - CD_MASK_ALL, - grease_pencil_dst->layers().size()); + CustomData_init_from(&grease_pencil_src->layers_data, + &grease_pencil_dst->layers_data, + CD_MASK_ALL, + grease_pencil_dst->layers().size()); BKE_defgroup_copy_list(&grease_pencil_dst->vertex_group_names, &grease_pencil_src->vertex_group_names); @@ -1837,10 +1837,10 @@ void BKE_grease_pencil_nomain_to_grease_pencil(GreasePencil *grease_pencil_src, __func__, grease_pencil_src->root_group_ptr->wrap()); BLI_assert(grease_pencil_src->layers().size() == grease_pencil_dst->layers().size()); - CustomData_copy(&grease_pencil_src->layers_data, - &grease_pencil_dst->layers_data, - eCustomDataMask(CD_MASK_ALL), - grease_pencil_src->layers().size()); + CustomData_init_from(&grease_pencil_src->layers_data, + &grease_pencil_dst->layers_data, + eCustomDataMask(CD_MASK_ALL), + grease_pencil_src->layers().size()); DEG_id_tag_update(&grease_pencil_dst->id, ID_RECALC_GEOMETRY); @@ -2979,7 +2979,7 @@ blender::bke::greasepencil::LayerGroup &GreasePencil::add_layer_group( static void reorder_customdata(CustomData &data, const Span new_by_old_map) { CustomData new_data; - CustomData_copy_layout(&data, &new_data, CD_MASK_ALL, CD_CONSTRUCT, new_by_old_map.size()); + CustomData_init_layout_from(&data, &new_data, CD_MASK_ALL, CD_CONSTRUCT, new_by_old_map.size()); for (const int old_i : new_by_old_map.index_range()) { const int new_i = new_by_old_map[old_i]; @@ -3306,7 +3306,7 @@ static void shrink_customdata(CustomData &data, const int index_to_remove, const { using namespace blender; CustomData new_data; - CustomData_copy_layout(&data, &new_data, CD_MASK_ALL, CD_CONSTRUCT, size); + CustomData_init_layout_from(&data, &new_data, CD_MASK_ALL, CD_CONSTRUCT, size); CustomData_realloc(&new_data, size, size - 1); const IndexRange range_before(index_to_remove); diff --git a/source/blender/blenkernel/intern/instances.cc b/source/blender/blenkernel/intern/instances.cc index 26aa1b1b2ea..93229262657 100644 --- a/source/blender/blenkernel/intern/instances.cc +++ b/source/blender/blenkernel/intern/instances.cc @@ -152,7 +152,7 @@ Instances::Instances(const Instances &other) reference_user_counts_(other.reference_user_counts_), almost_unique_ids_cache_(other.almost_unique_ids_cache_) { - CustomData_copy(&other.attributes_, &attributes_, CD_MASK_ALL, other.instances_num_); + CustomData_init_from(&other.attributes_, &attributes_, CD_MASK_ALL, other.instances_num_); } Instances::~Instances() diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc index 3737e404777..51c50e33139 100644 --- a/source/blender/blenkernel/intern/mesh.cc +++ b/source/blender/blenkernel/intern/mesh.cc @@ -176,17 +176,20 @@ static void mesh_copy_data(Main *bmain, mesh_dst->default_color_attribute = static_cast( MEM_dupallocN(mesh_src->default_color_attribute)); - CustomData_copy(&mesh_src->vert_data, &mesh_dst->vert_data, mask.vmask, mesh_dst->verts_num); - CustomData_copy(&mesh_src->edge_data, &mesh_dst->edge_data, mask.emask, mesh_dst->edges_num); - CustomData_copy( + CustomData_init_from( + &mesh_src->vert_data, &mesh_dst->vert_data, mask.vmask, mesh_dst->verts_num); + CustomData_init_from( + &mesh_src->edge_data, &mesh_dst->edge_data, mask.emask, mesh_dst->edges_num); + CustomData_init_from( &mesh_src->corner_data, &mesh_dst->corner_data, mask.lmask, mesh_dst->corners_num); - CustomData_copy(&mesh_src->face_data, &mesh_dst->face_data, mask.pmask, mesh_dst->faces_num); + CustomData_init_from( + &mesh_src->face_data, &mesh_dst->face_data, mask.pmask, mesh_dst->faces_num); blender::implicit_sharing::copy_shared_pointer(mesh_src->face_offset_indices, mesh_src->runtime->face_offsets_sharing_info, &mesh_dst->face_offset_indices, &mesh_dst->runtime->face_offsets_sharing_info); if (do_tessface) { - CustomData_copy( + CustomData_init_from( &mesh_src->fdata_legacy, &mesh_dst->fdata_legacy, mask.fmask, mesh_dst->totface_legacy); } else { @@ -816,16 +819,16 @@ Mesh *BKE_mesh_new_nomain_from_template_ex(const Mesh *me_src, BKE_mesh_copy_parameters_for_eval(me_dst, me_src); - CustomData_copy_layout( + CustomData_init_layout_from( &me_src->vert_data, &me_dst->vert_data, mask.vmask, CD_SET_DEFAULT, verts_num); - CustomData_copy_layout( + CustomData_init_layout_from( &me_src->edge_data, &me_dst->edge_data, mask.emask, CD_SET_DEFAULT, edges_num); - CustomData_copy_layout( + CustomData_init_layout_from( &me_src->face_data, &me_dst->face_data, mask.pmask, CD_SET_DEFAULT, faces_num); - CustomData_copy_layout( + CustomData_init_layout_from( &me_src->corner_data, &me_dst->corner_data, mask.lmask, CD_SET_DEFAULT, corners_num); if (do_tessface) { - CustomData_copy_layout( + CustomData_init_layout_from( &me_src->fdata_legacy, &me_dst->fdata_legacy, mask.fmask, CD_SET_DEFAULT, tessface_num); } else { diff --git a/source/blender/blenkernel/intern/mesh_convert.cc b/source/blender/blenkernel/intern/mesh_convert.cc index 88ab443d47e..46e7c7d153d 100644 --- a/source/blender/blenkernel/intern/mesh_convert.cc +++ b/source/blender/blenkernel/intern/mesh_convert.cc @@ -1071,10 +1071,13 @@ void BKE_mesh_nomain_to_mesh(Mesh *mesh_src, Mesh *mesh_dst, Object *ob) /* Using #CD_MASK_MESH ensures that only data that should exist in Main meshes is moved. */ const CustomData_MeshMasks mask = CD_MASK_MESH; - CustomData_copy(&mesh_src->vert_data, &mesh_dst->vert_data, mask.vmask, mesh_src->verts_num); - CustomData_copy(&mesh_src->edge_data, &mesh_dst->edge_data, mask.emask, mesh_src->edges_num); - CustomData_copy(&mesh_src->face_data, &mesh_dst->face_data, mask.pmask, mesh_src->faces_num); - CustomData_copy( + CustomData_init_from( + &mesh_src->vert_data, &mesh_dst->vert_data, mask.vmask, mesh_src->verts_num); + CustomData_init_from( + &mesh_src->edge_data, &mesh_dst->edge_data, mask.emask, mesh_src->edges_num); + CustomData_init_from( + &mesh_src->face_data, &mesh_dst->face_data, mask.pmask, mesh_src->faces_num); + CustomData_init_from( &mesh_src->corner_data, &mesh_dst->corner_data, mask.lmask, mesh_src->corners_num); std::swap(mesh_dst->face_offset_indices, mesh_src->face_offset_indices); std::swap(mesh_dst->runtime->face_offsets_sharing_info, diff --git a/source/blender/blenkernel/intern/mesh_legacy_convert.cc b/source/blender/blenkernel/intern/mesh_legacy_convert.cc index 7e38b8bed33..ec87be200b5 100644 --- a/source/blender/blenkernel/intern/mesh_legacy_convert.cc +++ b/source/blender/blenkernel/intern/mesh_legacy_convert.cc @@ -2092,7 +2092,7 @@ void BKE_mesh_legacy_convert_polys_to_offsets(Mesh *mesh) }); CustomData old_poly_data = mesh->face_data; CustomData_reset(&mesh->face_data); - CustomData_copy_layout( + CustomData_init_layout_from( &old_poly_data, &mesh->face_data, CD_MASK_MESH.pmask, CD_CONSTRUCT, mesh->faces_num); int offset = 0; diff --git a/source/blender/blenkernel/intern/mesh_legacy_derived_mesh.cc b/source/blender/blenkernel/intern/mesh_legacy_derived_mesh.cc index 525d69a9832..43af204b019 100644 --- a/source/blender/blenkernel/intern/mesh_legacy_derived_mesh.cc +++ b/source/blender/blenkernel/intern/mesh_legacy_derived_mesh.cc @@ -131,12 +131,16 @@ void DM_from_template(DerivedMesh *dm, int numPolys) { const CustomData_MeshMasks *mask = &CD_MASK_DERIVEDMESH; - CustomData_copy_layout(&source->vertData, &dm->vertData, mask->vmask, CD_SET_DEFAULT, numVerts); - CustomData_copy_layout(&source->edgeData, &dm->edgeData, mask->emask, CD_SET_DEFAULT, numEdges); - CustomData_copy_layout( + CustomData_init_layout_from( + &source->vertData, &dm->vertData, mask->vmask, CD_SET_DEFAULT, numVerts); + CustomData_init_layout_from( + &source->edgeData, &dm->edgeData, mask->emask, CD_SET_DEFAULT, numEdges); + CustomData_init_layout_from( &source->faceData, &dm->faceData, mask->fmask, CD_SET_DEFAULT, numTessFaces); - CustomData_copy_layout(&source->loopData, &dm->loopData, mask->lmask, CD_SET_DEFAULT, numLoops); - CustomData_copy_layout(&source->polyData, &dm->polyData, mask->pmask, CD_SET_DEFAULT, numPolys); + CustomData_init_layout_from( + &source->loopData, &dm->loopData, mask->lmask, CD_SET_DEFAULT, numLoops); + CustomData_init_layout_from( + &source->polyData, &dm->polyData, mask->pmask, CD_SET_DEFAULT, numPolys); dm->face_offsets = static_cast(MEM_dupallocN(source->face_offsets)); dm->type = type; diff --git a/source/blender/blenkernel/intern/pointcloud.cc b/source/blender/blenkernel/intern/pointcloud.cc index 3be0261ffff..416ded2fe59 100644 --- a/source/blender/blenkernel/intern/pointcloud.cc +++ b/source/blender/blenkernel/intern/pointcloud.cc @@ -79,7 +79,7 @@ static void pointcloud_copy_data(Main * /*bmain*/, const PointCloud *pointcloud_src = (const PointCloud *)id_src; pointcloud_dst->mat = static_cast(MEM_dupallocN(pointcloud_src->mat)); - CustomData_copy( + CustomData_init_from( &pointcloud_src->pdata, &pointcloud_dst->pdata, CD_MASK_ALL, pointcloud_dst->totpoint); pointcloud_dst->runtime = new blender::bke::PointCloudRuntime(); @@ -253,7 +253,7 @@ void BKE_pointcloud_nomain_to_pointcloud(PointCloud *pointcloud_src, PointCloud CustomData_free(&pointcloud_dst->pdata, pointcloud_dst->totpoint); const int totpoint = pointcloud_dst->totpoint = pointcloud_src->totpoint; - CustomData_copy(&pointcloud_src->pdata, &pointcloud_dst->pdata, CD_MASK_ALL, totpoint); + CustomData_init_from(&pointcloud_src->pdata, &pointcloud_dst->pdata, CD_MASK_ALL, totpoint); BKE_id_free(nullptr, pointcloud_src); } diff --git a/source/blender/blenkernel/intern/subdiv_mesh.cc b/source/blender/blenkernel/intern/subdiv_mesh.cc index 90e6ea8bd87..df9426a0282 100644 --- a/source/blender/blenkernel/intern/subdiv_mesh.cc +++ b/source/blender/blenkernel/intern/subdiv_mesh.cc @@ -227,11 +227,11 @@ static void vertex_interpolation_init(const SubdivMeshContext *ctx, else { vertex_interpolation->vertex_data = &vertex_interpolation->vertex_data_storage; /* Allocate storage for loops corresponding to ptex corners. */ - CustomData_copy_layout(&ctx->coarse_mesh->vert_data, - &vertex_interpolation->vertex_data_storage, - CD_MASK_EVERYTHING.vmask, - CD_SET_DEFAULT, - 4); + CustomData_init_layout_from(&ctx->coarse_mesh->vert_data, + &vertex_interpolation->vertex_data_storage, + CD_MASK_EVERYTHING.vmask, + CD_SET_DEFAULT, + 4); /* Initialize indices. */ vertex_interpolation->vertex_indices[0] = 0; vertex_interpolation->vertex_indices[1] = 1; @@ -356,11 +356,11 @@ static void loop_interpolation_init(const SubdivMeshContext *ctx, else { loop_interpolation->corner_data = &loop_interpolation->corner_data_storage; /* Allocate storage for loops corresponding to ptex corners. */ - CustomData_copy_layout(&ctx->coarse_corner_data_interp, - &loop_interpolation->corner_data_storage, - CD_MASK_EVERYTHING.lmask, - CD_SET_DEFAULT, - 4); + CustomData_init_layout_from(&ctx->coarse_corner_data_interp, + &loop_interpolation->corner_data_storage, + CD_MASK_EVERYTHING.lmask, + CD_SET_DEFAULT, + 4); /* Initialize indices. */ loop_interpolation->loop_indices[0] = 0; loop_interpolation->loop_indices[1] = 1; @@ -549,33 +549,33 @@ static bool subdiv_mesh_topology_info(const ForeachContext *foreach_context, BKE_mesh_copy_parameters_for_eval(subdiv_context->subdiv_mesh, &coarse_mesh); CustomData_free(&subdiv_mesh.vert_data, 0); - CustomData_copy_layout( + CustomData_init_layout_from( &coarse_mesh.vert_data, &subdiv_mesh.vert_data, mask.vmask, CD_SET_DEFAULT, num_vertices); CustomData_free(&subdiv_mesh.edge_data, 0); - CustomData_copy_layout( + CustomData_init_layout_from( &coarse_mesh.edge_data, &subdiv_mesh.edge_data, mask.emask, CD_SET_DEFAULT, num_edges); CustomData_free(&subdiv_mesh.face_data, 0); - CustomData_copy_layout( + CustomData_init_layout_from( &coarse_mesh.face_data, &subdiv_mesh.face_data, mask.pmask, CD_SET_DEFAULT, num_faces); if (num_faces != 0) { subdiv_mesh.face_offsets_for_write().last() = num_loops; } /* Create corner data for interpolation without topology attributes. */ - CustomData_copy(&coarse_mesh.corner_data, - &subdiv_context->coarse_corner_data_interp, - mask.lmask, - coarse_mesh.corners_num); + CustomData_init_from(&coarse_mesh.corner_data, + &subdiv_context->coarse_corner_data_interp, + mask.lmask, + coarse_mesh.corners_num); CustomData_free_layer_named( &subdiv_context->coarse_corner_data_interp, ".corner_vert", coarse_mesh.corners_num); CustomData_free_layer_named( &subdiv_context->coarse_corner_data_interp, ".corner_edge", coarse_mesh.corners_num); CustomData_free(&subdiv_mesh.corner_data, 0); - CustomData_copy_layout(&subdiv_context->coarse_corner_data_interp, - &subdiv_mesh.corner_data, - mask.lmask, - CD_SET_DEFAULT, - num_loops); + CustomData_init_layout_from(&subdiv_context->coarse_corner_data_interp, + &subdiv_mesh.corner_data, + mask.lmask, + CD_SET_DEFAULT, + num_loops); /* Allocate corner topology arrays which are added to the result at the end. */ subdiv_context->subdiv_corner_verts = static_cast( diff --git a/source/blender/bmesh/intern/bmesh_construct.cc b/source/blender/bmesh/intern/bmesh_construct.cc index 160ac563216..7728021f37e 100644 --- a/source/blender/bmesh/intern/bmesh_construct.cc +++ b/source/blender/bmesh/intern/bmesh_construct.cc @@ -456,10 +456,14 @@ void BM_mesh_copy_init_customdata_from_mesh_array(BMesh *bm_dst, &me_src->corner_data, CD_MASK_BMESH.lmask); if (i == 0) { - CustomData_copy_layout(&mesh_vdata, &bm_dst->vdata, CD_MASK_BMESH.vmask, CD_SET_DEFAULT, 0); - CustomData_copy_layout(&mesh_edata, &bm_dst->edata, CD_MASK_BMESH.emask, CD_SET_DEFAULT, 0); - CustomData_copy_layout(&mesh_pdata, &bm_dst->pdata, CD_MASK_BMESH.pmask, CD_SET_DEFAULT, 0); - CustomData_copy_layout(&mesh_ldata, &bm_dst->ldata, CD_MASK_BMESH.lmask, CD_SET_DEFAULT, 0); + CustomData_init_layout_from( + &mesh_vdata, &bm_dst->vdata, CD_MASK_BMESH.vmask, CD_SET_DEFAULT, 0); + CustomData_init_layout_from( + &mesh_edata, &bm_dst->edata, CD_MASK_BMESH.emask, CD_SET_DEFAULT, 0); + CustomData_init_layout_from( + &mesh_pdata, &bm_dst->pdata, CD_MASK_BMESH.pmask, CD_SET_DEFAULT, 0); + CustomData_init_layout_from( + &mesh_ldata, &bm_dst->ldata, CD_MASK_BMESH.lmask, CD_SET_DEFAULT, 0); } else { CustomData_merge_layout(&mesh_vdata, &bm_dst->vdata, CD_MASK_BMESH.vmask, CD_SET_DEFAULT, 0); @@ -493,10 +497,14 @@ void BM_mesh_copy_init_customdata(BMesh *bm_dst, BMesh *bm_src, const BMAllocTem allocsize = &bm_mesh_allocsize_default; } - CustomData_copy_layout(&bm_src->vdata, &bm_dst->vdata, CD_MASK_BMESH.vmask, CD_SET_DEFAULT, 0); - CustomData_copy_layout(&bm_src->edata, &bm_dst->edata, CD_MASK_BMESH.emask, CD_SET_DEFAULT, 0); - CustomData_copy_layout(&bm_src->ldata, &bm_dst->ldata, CD_MASK_BMESH.lmask, CD_SET_DEFAULT, 0); - CustomData_copy_layout(&bm_src->pdata, &bm_dst->pdata, CD_MASK_BMESH.pmask, CD_SET_DEFAULT, 0); + CustomData_init_layout_from( + &bm_src->vdata, &bm_dst->vdata, CD_MASK_BMESH.vmask, CD_SET_DEFAULT, 0); + CustomData_init_layout_from( + &bm_src->edata, &bm_dst->edata, CD_MASK_BMESH.emask, CD_SET_DEFAULT, 0); + CustomData_init_layout_from( + &bm_src->ldata, &bm_dst->ldata, CD_MASK_BMESH.lmask, CD_SET_DEFAULT, 0); + CustomData_init_layout_from( + &bm_src->pdata, &bm_dst->pdata, CD_MASK_BMESH.pmask, CD_SET_DEFAULT, 0); CustomData_bmesh_init_pool(&bm_dst->vdata, allocsize->totvert, BM_VERT); CustomData_bmesh_init_pool(&bm_dst->edata, allocsize->totedge, BM_EDGE); diff --git a/source/blender/bmesh/intern/bmesh_mesh_convert.cc b/source/blender/bmesh/intern/bmesh_mesh_convert.cc index a199a0b0975..91948d81a23 100644 --- a/source/blender/bmesh/intern/bmesh_mesh_convert.cc +++ b/source/blender/bmesh/intern/bmesh_mesh_convert.cc @@ -277,10 +277,10 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *mesh, const BMeshFromMeshParams * if (mesh->verts_num == 0) { if (is_new) { /* No verts? still copy custom-data layout. */ - CustomData_copy_layout(&mesh_vdata, &bm->vdata, mask.vmask, CD_CONSTRUCT, 0); - CustomData_copy_layout(&mesh_edata, &bm->edata, mask.emask, CD_CONSTRUCT, 0); - CustomData_copy_layout(&mesh_pdata, &bm->pdata, mask.pmask, CD_CONSTRUCT, 0); - CustomData_copy_layout(&mesh_ldata, &bm->ldata, mask.lmask, CD_CONSTRUCT, 0); + CustomData_init_layout_from(&mesh_vdata, &bm->vdata, mask.vmask, CD_CONSTRUCT, 0); + CustomData_init_layout_from(&mesh_edata, &bm->edata, mask.emask, CD_CONSTRUCT, 0); + CustomData_init_layout_from(&mesh_pdata, &bm->pdata, mask.pmask, CD_CONSTRUCT, 0); + CustomData_init_layout_from(&mesh_ldata, &bm->ldata, mask.lmask, CD_CONSTRUCT, 0); CustomData_bmesh_init_pool(&bm->vdata, mesh->verts_num, BM_VERT); CustomData_bmesh_init_pool(&bm->edata, mesh->edges_num, BM_EDGE); @@ -296,10 +296,10 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *mesh, const BMeshFromMeshParams * } if (is_new) { - CustomData_copy_layout(&mesh_vdata, &bm->vdata, mask.vmask, CD_SET_DEFAULT, 0); - CustomData_copy_layout(&mesh_edata, &bm->edata, mask.emask, CD_SET_DEFAULT, 0); - CustomData_copy_layout(&mesh_pdata, &bm->pdata, mask.pmask, CD_SET_DEFAULT, 0); - CustomData_copy_layout(&mesh_ldata, &bm->ldata, mask.lmask, CD_SET_DEFAULT, 0); + CustomData_init_layout_from(&mesh_vdata, &bm->vdata, mask.vmask, CD_SET_DEFAULT, 0); + CustomData_init_layout_from(&mesh_edata, &bm->edata, mask.emask, CD_SET_DEFAULT, 0); + CustomData_init_layout_from(&mesh_pdata, &bm->pdata, mask.pmask, CD_SET_DEFAULT, 0); + CustomData_init_layout_from(&mesh_ldata, &bm->ldata, mask.lmask, CD_SET_DEFAULT, 0); } else { CustomData_bmesh_merge_layout( @@ -1468,13 +1468,13 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *mesh, const BMeshToMeshParam { CustomData_MeshMasks mask = CD_MASK_MESH; CustomData_MeshMasks_update(&mask, ¶ms->cd_mask_extra); - CustomData_copy_layout( + CustomData_init_layout_from( &bm->vdata, &mesh->vert_data, mask.vmask, CD_CONSTRUCT, mesh->verts_num); - CustomData_copy_layout( + CustomData_init_layout_from( &bm->edata, &mesh->edge_data, mask.emask, CD_CONSTRUCT, mesh->edges_num); - CustomData_copy_layout( + CustomData_init_layout_from( &bm->ldata, &mesh->corner_data, mask.lmask, CD_CONSTRUCT, mesh->corners_num); - CustomData_copy_layout( + CustomData_init_layout_from( &bm->pdata, &mesh->face_data, mask.pmask, CD_CONSTRUCT, mesh->faces_num); } diff --git a/source/blender/editors/grease_pencil/intern/grease_pencil_undo.cc b/source/blender/editors/grease_pencil/intern/grease_pencil_undo.cc index 25eb62bb3d2..4e3fb9804d0 100644 --- a/source/blender/editors/grease_pencil/intern/grease_pencil_undo.cc +++ b/source/blender/editors/grease_pencil/intern/grease_pencil_undo.cc @@ -261,7 +261,7 @@ class StepObject { { layers_num_ = int(grease_pencil.layers().size()); - CustomData_copy( + CustomData_init_from( &grease_pencil.layers_data, &layers_data_, eCustomDataMask(CD_MASK_ALL), layers_num_); if (grease_pencil.active_node != nullptr) { @@ -289,7 +289,7 @@ class StepObject { } CustomData_free(&grease_pencil.layers_data, layers_num_); - CustomData_copy( + CustomData_init_from( &layers_data_, &grease_pencil.layers_data, eCustomDataMask(CD_MASK_ALL), layers_num_); } diff --git a/source/blender/editors/mesh/mesh_data.cc b/source/blender/editors/mesh/mesh_data.cc index daba95d2fe3..7186770dd70 100644 --- a/source/blender/editors/mesh/mesh_data.cc +++ b/source/blender/editors/mesh/mesh_data.cc @@ -799,7 +799,7 @@ static void mesh_add_verts(Mesh *mesh, int len) int totvert = mesh->verts_num + len; CustomData vert_data; - CustomData_copy_layout( + CustomData_init_layout_from( &mesh->vert_data, &vert_data, CD_MASK_MESH.vmask, CD_SET_DEFAULT, totvert); CustomData_copy_data(&mesh->vert_data, &vert_data, 0, 0, mesh->verts_num); @@ -834,7 +834,7 @@ static void mesh_add_edges(Mesh *mesh, int len) totedge = mesh->edges_num + len; /* Update custom-data. */ - CustomData_copy_layout( + CustomData_init_layout_from( &mesh->edge_data, &edge_data, CD_MASK_MESH.emask, CD_SET_DEFAULT, totedge); CustomData_copy_data(&mesh->edge_data, &edge_data, 0, 0, mesh->edges_num); @@ -869,7 +869,8 @@ static void mesh_add_loops(Mesh *mesh, int len) totloop = mesh->corners_num + len; /* new face count */ /* update customdata */ - CustomData_copy_layout(&mesh->corner_data, &ldata, CD_MASK_MESH.lmask, CD_SET_DEFAULT, totloop); + CustomData_init_layout_from( + &mesh->corner_data, &ldata, CD_MASK_MESH.lmask, CD_SET_DEFAULT, totloop); CustomData_copy_data(&mesh->corner_data, &ldata, 0, 0, mesh->corners_num); if (!CustomData_has_layer_named(&ldata, CD_PROP_INT32, ".corner_vert")) { @@ -906,7 +907,7 @@ static void mesh_add_faces(Mesh *mesh, int len) faces_num = mesh->faces_num + len; /* new face count */ /* update customdata */ - CustomData_copy_layout( + CustomData_init_layout_from( &mesh->face_data, &face_data, CD_MASK_MESH.pmask, CD_SET_DEFAULT, faces_num); CustomData_copy_data(&mesh->face_data, &face_data, 0, 0, mesh->faces_num); diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.cc b/source/blender/editors/sculpt_paint/sculpt_undo.cc index 5c56dedb1f4..e0275836b73 100644 --- a/source/blender/editors/sculpt_paint/sculpt_undo.cc +++ b/source/blender/editors/sculpt_paint/sculpt_undo.cc @@ -680,11 +680,14 @@ static void store_geometry_data(NodeGeometry *geometry, const Object &object) BLI_assert(!geometry->is_initialized); geometry->is_initialized = true; - CustomData_copy(&mesh->vert_data, &geometry->vert_data, CD_MASK_MESH.vmask, mesh->verts_num); - CustomData_copy(&mesh->edge_data, &geometry->edge_data, CD_MASK_MESH.emask, mesh->edges_num); - CustomData_copy( + CustomData_init_from( + &mesh->vert_data, &geometry->vert_data, CD_MASK_MESH.vmask, mesh->verts_num); + CustomData_init_from( + &mesh->edge_data, &geometry->edge_data, CD_MASK_MESH.emask, mesh->edges_num); + CustomData_init_from( &mesh->corner_data, &geometry->corner_data, CD_MASK_MESH.lmask, mesh->corners_num); - CustomData_copy(&mesh->face_data, &geometry->face_data, CD_MASK_MESH.pmask, mesh->faces_num); + CustomData_init_from( + &mesh->face_data, &geometry->face_data, CD_MASK_MESH.pmask, mesh->faces_num); implicit_sharing::copy_shared_pointer(mesh->face_offset_indices, mesh->runtime->face_offsets_sharing_info, &geometry->face_offset_indices, @@ -708,11 +711,14 @@ static void restore_geometry_data(const NodeGeometry *geometry, Mesh *mesh) mesh->faces_num = geometry->faces_num; mesh->totface_legacy = 0; - CustomData_copy(&geometry->vert_data, &mesh->vert_data, CD_MASK_MESH.vmask, geometry->totvert); - CustomData_copy(&geometry->edge_data, &mesh->edge_data, CD_MASK_MESH.emask, geometry->totedge); - CustomData_copy( + CustomData_init_from( + &geometry->vert_data, &mesh->vert_data, CD_MASK_MESH.vmask, geometry->totvert); + CustomData_init_from( + &geometry->edge_data, &mesh->edge_data, CD_MASK_MESH.emask, geometry->totedge); + CustomData_init_from( &geometry->corner_data, &mesh->corner_data, CD_MASK_MESH.lmask, geometry->totloop); - CustomData_copy(&geometry->face_data, &mesh->face_data, CD_MASK_MESH.pmask, geometry->faces_num); + CustomData_init_from( + &geometry->face_data, &mesh->face_data, CD_MASK_MESH.pmask, geometry->faces_num); implicit_sharing::copy_shared_pointer(geometry->face_offset_indices, geometry->face_offsets_sharing_info, &mesh->face_offset_indices, diff --git a/source/blender/geometry/intern/randomize.cc b/source/blender/geometry/intern/randomize.cc index 54ebbffe42b..46a0f2c045d 100644 --- a/source/blender/geometry/intern/randomize.cc +++ b/source/blender/geometry/intern/randomize.cc @@ -74,7 +74,7 @@ static int seed_from_instances(const bke::Instances &instances) static void reorder_customdata(CustomData &data, const Span new_by_old_map) { CustomData new_data; - CustomData_copy_layout(&data, &new_data, CD_MASK_ALL, CD_CONSTRUCT, new_by_old_map.size()); + CustomData_init_layout_from(&data, &new_data, CD_MASK_ALL, CD_CONSTRUCT, new_by_old_map.size()); for (const int old_i : new_by_old_map.index_range()) { const int new_i = new_by_old_map[old_i]; @@ -143,7 +143,7 @@ static void reorder_customdata_groups(CustomData &data, const int elements_num = new_offsets.total_size(); const int groups_num = new_by_old_map.size(); CustomData new_data; - CustomData_copy_layout(&data, &new_data, CD_MASK_ALL, CD_CONSTRUCT, elements_num); + CustomData_init_layout_from(&data, &new_data, CD_MASK_ALL, CD_CONSTRUCT, elements_num); for (const int old_i : IndexRange(groups_num)) { const int new_i = new_by_old_map[old_i]; const IndexRange old_range = old_offsets[old_i]; diff --git a/source/blender/io/collada/MeshImporter.cpp b/source/blender/io/collada/MeshImporter.cpp index b2c672198ea..311876fdb50 100644 --- a/source/blender/io/collada/MeshImporter.cpp +++ b/source/blender/io/collada/MeshImporter.cpp @@ -557,7 +557,7 @@ void MeshImporter::mesh_add_edges(Mesh *mesh, int len) totedge = mesh->edges_num + len; /* Update custom-data. */ - CustomData_copy_layout( + CustomData_init_layout_from( &mesh->edge_data, &edge_data, CD_MASK_MESH.emask, CD_SET_DEFAULT, totedge); CustomData_copy_data(&mesh->edge_data, &edge_data, 0, 0, mesh->edges_num);