diff --git a/source/blender/modifiers/intern/MOD_array.cc b/source/blender/modifiers/intern/MOD_array.cc index e0c1165193e..7d2779a7b7b 100644 --- a/source/blender/modifiers/intern/MOD_array.cc +++ b/source/blender/modifiers/intern/MOD_array.cc @@ -166,10 +166,10 @@ static void dm_mvert_map_doubles(int *doubles_map, source_end = source_start + source_verts_num; /* build array of MVerts to be tested for merging */ - SortVertsElem *sorted_verts_target = static_cast( - MEM_malloc_arrayN(target_verts_num, sizeof(SortVertsElem), __func__)); - SortVertsElem *sorted_verts_source = static_cast( - MEM_malloc_arrayN(source_verts_num, sizeof(SortVertsElem), __func__)); + SortVertsElem *sorted_verts_target = MEM_malloc_arrayN(size_t(target_verts_num), + __func__); + SortVertsElem *sorted_verts_source = MEM_malloc_arrayN(size_t(source_verts_num), + __func__); /* Copy target vertices index and cos into SortVertsElem array */ svert_from_mvert(sorted_verts_target, vert_positions, target_start, target_end); @@ -567,7 +567,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd, if (use_merge) { /* Will need full_doubles_map for handling merge */ - full_doubles_map = static_cast(MEM_malloc_arrayN(result_nverts, sizeof(int), __func__)); + full_doubles_map = MEM_malloc_arrayN(size_t(result_nverts), __func__); copy_vn_i(full_doubles_map, result_nverts, -1); } diff --git a/source/blender/modifiers/intern/MOD_boolean.cc b/source/blender/modifiers/intern/MOD_boolean.cc index b51ecdf8555..16832bd8620 100644 --- a/source/blender/modifiers/intern/MOD_boolean.cc +++ b/source/blender/modifiers/intern/MOD_boolean.cc @@ -490,7 +490,7 @@ static Mesh *exact_boolean_mesh(BooleanModifierData *bmd, if (material_mode == eBooleanModifierMaterialMode_Transfer) { MEM_SAFE_FREE(result->mat); - result->mat = (Material **)MEM_malloc_arrayN(materials.size(), sizeof(Material *), __func__); + result->mat = MEM_malloc_arrayN(size_t(materials.size()), __func__); result->totcol = materials.size(); MutableSpan(result->mat, result->totcol).copy_from(materials); } diff --git a/source/blender/modifiers/intern/MOD_build.cc b/source/blender/modifiers/intern/MOD_build.cc index 37caa29fa67..1c74f22fb16 100644 --- a/source/blender/modifiers/intern/MOD_build.cc +++ b/source/blender/modifiers/intern/MOD_build.cc @@ -70,9 +70,9 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh const blender::Span corner_verts_src = mesh->corner_verts(); const blender::Span corner_edges_src = mesh->corner_edges(); - int *vertMap = static_cast(MEM_malloc_arrayN(vert_src_num, sizeof(int), __func__)); - int *edgeMap = static_cast(MEM_malloc_arrayN(edges_src.size(), sizeof(int), __func__)); - int *faceMap = static_cast(MEM_malloc_arrayN(faces_src.size(), sizeof(int), __func__)); + int *vertMap = MEM_malloc_arrayN(size_t(vert_src_num), __func__); + int *edgeMap = MEM_malloc_arrayN(size_t(edges_src.size()), __func__); + int *faceMap = MEM_malloc_arrayN(size_t(faces_src.size()), __func__); range_vn_i(vertMap, vert_src_num, 0); range_vn_i(edgeMap, edges_src.size(), 0); diff --git a/source/blender/modifiers/intern/MOD_collision.cc b/source/blender/modifiers/intern/MOD_collision.cc index 414a8a0524b..083b96b2429 100644 --- a/source/blender/modifiers/intern/MOD_collision.cc +++ b/source/blender/modifiers/intern/MOD_collision.cc @@ -124,8 +124,7 @@ static void deform_verts(ModifierData *md, if (collmd->time_xnew == -1000) { /* first time */ mvert_num = mesh->verts_num; - collmd->x = static_cast( - MEM_malloc_arrayN(mvert_num, sizeof(float[3]), __func__)); + collmd->x = MEM_malloc_arrayN(size_t(mvert_num), __func__); blender::MutableSpan(reinterpret_cast(collmd->x), mvert_num) .copy_from(mesh->vert_positions()); @@ -144,8 +143,7 @@ static void deform_verts(ModifierData *md, { const blender::Span corner_tris = mesh->corner_tris(); collmd->tri_num = corner_tris.size(); - int(*vert_tris)[3] = static_cast( - MEM_malloc_arrayN(collmd->tri_num, sizeof(int[3]), __func__)); + int(*vert_tris)[3] = MEM_malloc_arrayN(collmd->tri_num, __func__); blender::bke::mesh::vert_tris_from_corner_tris( mesh->corner_verts(), corner_tris, @@ -255,9 +253,9 @@ static void blend_read(BlendDataReader * /*reader*/, ModifierData *md) collmd->xnew = newdataadr(fd, collmd->xnew); collmd->mfaces = newdataadr(fd, collmd->mfaces); - collmd->current_x = MEM_calloc_arrayN(collmd->mvert_num, sizeof(float[3]), "current_x"); - collmd->current_xnew = MEM_calloc_arrayN(collmd->mvert_num, sizeof(float[3]), "current_xnew"); - collmd->current_v = MEM_calloc_arrayN(collmd->mvert_num, sizeof(float[3]), "current_v"); + collmd->current_x = MEM_calloc_arrayN(collmd->mvert_num, "current_x"); + collmd->current_xnew = MEM_calloc_arrayN(collmd->mvert_num, "current_xnew"); + collmd->current_v = MEM_calloc_arrayN(collmd->mvert_num, "current_v"); #endif collmd->x = nullptr; diff --git a/source/blender/modifiers/intern/MOD_correctivesmooth.cc b/source/blender/modifiers/intern/MOD_correctivesmooth.cc index e12d40263b8..4da01e708db 100644 --- a/source/blender/modifiers/intern/MOD_correctivesmooth.cc +++ b/source/blender/modifiers/intern/MOD_correctivesmooth.cc @@ -127,8 +127,7 @@ static void mesh_get_boundaries(Mesh *mesh, float *smooth_weights) const blender::Span corner_edges = mesh->corner_edges(); /* Flag boundary edges so only boundaries are set to 1. */ - uint8_t *boundaries = static_cast( - MEM_calloc_arrayN(size_t(edges.size()), sizeof(*boundaries), __func__)); + uint8_t *boundaries = MEM_calloc_arrayN(size_t(edges.size()), __func__); for (const int64_t i : faces.index_range()) { for (const int edge : corner_edges.slice(faces[i])) { @@ -170,8 +169,7 @@ static void smooth_iter__simple(CorrectiveSmoothModifierData *csmd, SmoothingData_Simple *smooth_data = MEM_calloc_arrayN( size_t(vertexCos.size()), __func__); - float *vertex_edge_count_div = static_cast( - MEM_calloc_arrayN(size_t(vertexCos.size()), sizeof(float), __func__)); + float *vertex_edge_count_div = MEM_calloc_arrayN(size_t(vertexCos.size()), __func__); /* calculate as floats to avoid int->float conversion in #smooth_iter */ for (i = 0; i < edges_num; i++) { @@ -251,8 +249,7 @@ static void smooth_iter__length_weight(CorrectiveSmoothModifierData *csmd, size_t(vertexCos.size()), __func__); /* calculate as floats to avoid int->float conversion in #smooth_iter */ - float *vertex_edge_count = static_cast( - MEM_calloc_arrayN(size_t(vertexCos.size()), sizeof(float), __func__)); + float *vertex_edge_count = MEM_calloc_arrayN(size_t(vertexCos.size()), __func__); for (i = 0; i < edges_num; i++) { vertex_edge_count[edges[i][0]] += 1.0f; vertex_edge_count[edges[i][1]] += 1.0f; @@ -352,8 +349,7 @@ static void smooth_verts(CorrectiveSmoothModifierData *csmd, if (dvert || (csmd->flag & MOD_CORRECTIVESMOOTH_PIN_BOUNDARY)) { - smooth_weights = static_cast( - MEM_malloc_arrayN(size_t(vertexCos.size()), sizeof(float), __func__)); + smooth_weights = MEM_malloc_arrayN(size_t(vertexCos.size()), __func__); if (dvert) { mesh_get_weights(dvert, @@ -514,8 +510,8 @@ static void calc_deltas(CorrectiveSmoothModifierData *csmd, uint l_index; - float(*tangent_spaces)[3][3] = static_cast( - MEM_malloc_arrayN(size_t(corner_verts.size()), sizeof(float[3][3]), __func__)); + float(*tangent_spaces)[3][3] = MEM_malloc_arrayN(size_t(corner_verts.size()), + __func__); if (csmd->delta_cache.deltas_num != uint(corner_verts.size())) { MEM_SAFE_FREE(csmd->delta_cache.deltas); @@ -524,8 +520,7 @@ static void calc_deltas(CorrectiveSmoothModifierData *csmd, /* allocate deltas if they have not yet been allocated, otherwise we will just write over them */ if (!csmd->delta_cache.deltas) { csmd->delta_cache.deltas_num = uint(corner_verts.size()); - csmd->delta_cache.deltas = static_cast( - MEM_malloc_arrayN(size_t(corner_verts.size()), sizeof(float[3]), __func__)); + csmd->delta_cache.deltas = MEM_malloc_arrayN(size_t(corner_verts.size()), __func__); } smooth_verts(csmd, mesh, dvert, defgrp_index, smooth_vertex_coords); @@ -579,8 +574,7 @@ static void correctivesmooth_modifier_do(ModifierData *md, { if (DEG_is_active(depsgraph)) { BLI_assert(csmd->bind_coords == nullptr); - csmd->bind_coords = static_cast( - MEM_malloc_arrayN(size_t(vertexCos.size()), sizeof(float[3]), __func__)); + csmd->bind_coords = MEM_malloc_arrayN(size_t(vertexCos.size()), __func__); memcpy(csmd->bind_coords, vertexCos.data(), size_t(vertexCos.size_in_bytes())); csmd->bind_coords_num = uint(vertexCos.size()); BLI_assert(csmd->bind_coords != nullptr); @@ -691,12 +685,11 @@ static void correctivesmooth_modifier_do(ModifierData *md, const float scale = csmd->scale; - float(*tangent_spaces)[3][3] = static_cast( - MEM_malloc_arrayN(size_t(corner_verts.size()), sizeof(float[3][3]), __func__)); - float *tangent_weights = static_cast( - MEM_malloc_arrayN(size_t(corner_verts.size()), sizeof(float), __func__)); - float *tangent_weights_per_vertex = static_cast( - MEM_malloc_arrayN(size_t(vertexCos.size()), sizeof(float), __func__)); + float(*tangent_spaces)[3][3] = MEM_malloc_arrayN(size_t(corner_verts.size()), + __func__); + float *tangent_weights = MEM_malloc_arrayN(size_t(corner_verts.size()), __func__); + float *tangent_weights_per_vertex = MEM_malloc_arrayN(size_t(vertexCos.size()), + __func__); calc_tangent_spaces( mesh, vertexCos, tangent_spaces, tangent_weights, tangent_weights_per_vertex); diff --git a/source/blender/modifiers/intern/MOD_decimate.cc b/source/blender/modifiers/intern/MOD_decimate.cc index 81e9d2271f6..d6a44d56600 100644 --- a/source/blender/modifiers/intern/MOD_decimate.cc +++ b/source/blender/modifiers/intern/MOD_decimate.cc @@ -142,7 +142,7 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh const uint vert_tot = mesh->verts_num; uint i; - vweights = static_cast(MEM_malloc_arrayN(vert_tot, sizeof(float), __func__)); + vweights = MEM_malloc_arrayN(vert_tot, __func__); if (dmd->flag & MOD_DECIM_FLAG_INVERT_VGROUP) { for (i = 0; i < vert_tot; i++) { diff --git a/source/blender/modifiers/intern/MOD_displace.cc b/source/blender/modifiers/intern/MOD_displace.cc index ed35b1670a4..dbebc40377f 100644 --- a/source/blender/modifiers/intern/MOD_displace.cc +++ b/source/blender/modifiers/intern/MOD_displace.cc @@ -277,8 +277,7 @@ static void displaceModifier_do(DisplaceModifierData *dmd, Tex *tex_target = dmd->texture; if (tex_target != nullptr) { - tex_co = static_cast(MEM_calloc_arrayN( - size_t(positions.size()), sizeof(*tex_co), "displaceModifier_do tex_co")); + tex_co = MEM_calloc_arrayN(size_t(positions.size()), "displaceModifier_do tex_co"); MOD_get_texture_coords((MappingInfoModifierData *)dmd, ctx, ob, @@ -294,8 +293,7 @@ static void displaceModifier_do(DisplaceModifierData *dmd, if (direction == MOD_DISP_DIR_CLNOR) { if (mesh->attributes().contains("custom_normal")) { - vert_clnors = static_cast( - MEM_malloc_arrayN(positions.size(), sizeof(*vert_clnors), __func__)); + vert_clnors = MEM_malloc_arrayN(size_t(positions.size()), __func__); BKE_mesh_normals_loop_to_vertex( positions.size(), mesh->corner_verts().data(), diff --git a/source/blender/modifiers/intern/MOD_explode.cc b/source/blender/modifiers/intern/MOD_explode.cc index dea9e032453..293ab4ee6cb 100644 --- a/source/blender/modifiers/intern/MOD_explode.cc +++ b/source/blender/modifiers/intern/MOD_explode.cc @@ -108,9 +108,9 @@ static void createFacepa(ExplodeModifierData *emd, ParticleSystemModifierData *p if (emd->facepa) { MEM_freeN(emd->facepa); } - facepa = emd->facepa = static_cast(MEM_calloc_arrayN(totface, sizeof(int), __func__)); + facepa = emd->facepa = MEM_calloc_arrayN(size_t(totface), __func__); - vertpa = static_cast(MEM_calloc_arrayN(totvert, sizeof(int), __func__)); + vertpa = MEM_calloc_arrayN(size_t(totvert), __func__); /* initialize all faces & verts to no particle */ for (i = 0; i < totface; i++) { @@ -656,8 +656,8 @@ static Mesh *cutEdges(ExplodeModifierData *emd, Mesh *mesh) int totvert = mesh->verts_num; int totface = mesh->totface_legacy; - int *facesplit = static_cast(MEM_calloc_arrayN(totface, sizeof(int), __func__)); - int *vertpa = static_cast(MEM_calloc_arrayN(totvert, sizeof(int), __func__)); + int *facesplit = MEM_calloc_arrayN(size_t(totface), __func__); + int *vertpa = MEM_calloc_arrayN(size_t(totvert), __func__); int *facepa = emd->facepa; int *fs, totfsplit = 0, curdupface = 0; int i, v1, v2, v3, v4, v[4] = {0, 0, 0, 0}, /* To quite gcc barking... */ @@ -746,8 +746,7 @@ static Mesh *cutEdges(ExplodeModifierData *emd, Mesh *mesh) * later interpreted as triangles, for this to work right I think we probably * have to stop using tessface. */ - facepa = static_cast( - MEM_calloc_arrayN((totface + (totfsplit * 2)), sizeof(int), __func__)); + facepa = MEM_calloc_arrayN(size_t(totface) + (size_t(totfsplit) * 2), __func__); // memcpy(facepa, emd->facepa, totface*sizeof(int)); emd->facepa = facepa; diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_dash.cc b/source/blender/modifiers/intern/MOD_grease_pencil_dash.cc index 2083a308dd1..7323edef916 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_dash.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_dash.cc @@ -477,8 +477,7 @@ static void panel_register(ARegionType *region_type) { modifier_panel_register(region_type, eModifierType_GreasePencilDash, panel_draw); - uiListType *list_type = static_cast( - MEM_callocN(sizeof(uiListType), "Grease Pencil Dash modifier segments")); + uiListType *list_type = MEM_callocN("Grease Pencil Dash modifier segments"); STRNCPY(list_type->idname, "MOD_UL_grease_pencil_dash_modifier_segments"); list_type->draw_item = segment_list_item_draw; WM_uilisttype_add(list_type); diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_time.cc b/source/blender/modifiers/intern/MOD_grease_pencil_time.cc index 37135bb4aa1..4937bcd8cbc 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_time.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_time.cc @@ -638,8 +638,7 @@ static void panel_register(ARegionType *region_type) { modifier_panel_register(region_type, eModifierType_GreasePencilTime, panel_draw); - uiListType *list_type = static_cast( - MEM_callocN(sizeof(uiListType), "Grease Pencil Time modifier segments")); + uiListType *list_type = MEM_callocN("Grease Pencil Time modifier segments"); STRNCPY(list_type->idname, "MOD_UL_grease_pencil_time_modifier_segments"); list_type->draw_item = segment_list_item_draw; WM_uilisttype_add(list_type); diff --git a/source/blender/modifiers/intern/MOD_laplaciandeform.cc b/source/blender/modifiers/intern/MOD_laplaciandeform.cc index 3748ce468f6..7056d7e99aa 100644 --- a/source/blender/modifiers/intern/MOD_laplaciandeform.cc +++ b/source/blender/modifiers/intern/MOD_laplaciandeform.cc @@ -125,12 +125,12 @@ static LaplacianSystem *initLaplacianSystem(int verts_num, sys->anchors_num = anchors_num; sys->repeat = iterations; STRNCPY(sys->anchor_grp_name, defgrpName); - sys->co = static_cast(MEM_malloc_arrayN(verts_num, sizeof(float[3]), __func__)); - sys->no = static_cast(MEM_calloc_arrayN(verts_num, sizeof(float[3]), __func__)); - sys->delta = static_cast(MEM_calloc_arrayN(verts_num, sizeof(float[3]), __func__)); - sys->tris = static_cast(MEM_malloc_arrayN(tris_num, sizeof(int[3]), __func__)); - sys->index_anchors = static_cast(MEM_malloc_arrayN((anchors_num), sizeof(int), __func__)); - sys->unit_verts = static_cast(MEM_calloc_arrayN(verts_num, sizeof(int), __func__)); + sys->co = MEM_malloc_arrayN(size_t(verts_num), __func__); + sys->no = MEM_calloc_arrayN(size_t(verts_num), __func__); + sys->delta = MEM_calloc_arrayN(size_t(verts_num), __func__); + sys->tris = MEM_malloc_arrayN(size_t(tris_num), __func__); + sys->index_anchors = MEM_malloc_arrayN(size_t(anchors_num), __func__); + sys->unit_verts = MEM_calloc_arrayN(size_t(verts_num), __func__); return sys; } @@ -543,8 +543,7 @@ static void initSystem( const bool invert_vgroup = (lmd->flag & MOD_LAPLACIANDEFORM_INVERT_VGROUP) != 0; if (isValidVertexGroup(lmd, ob, mesh)) { - int *index_anchors = static_cast( - MEM_malloc_arrayN(verts_num, sizeof(int), __func__)); /* Over-allocate. */ + int *index_anchors = MEM_malloc_arrayN(size_t(verts_num), __func__); /* Over-allocate. */ STACK_DECLARE(index_anchors); @@ -577,7 +576,7 @@ static void initSystem( memcpy(sys->index_anchors, index_anchors, sizeof(int) * anchors_num); memcpy(sys->co, vertexCos, sizeof(float[3]) * verts_num); MEM_freeN(index_anchors); - lmd->vertexco = static_cast(MEM_malloc_arrayN(verts_num, sizeof(float[3]), __func__)); + lmd->vertexco = MEM_malloc_arrayN(3 * size_t(verts_num), __func__); memcpy(lmd->vertexco, vertexCos, sizeof(float[3]) * verts_num); lmd->verts_num = verts_num; @@ -658,8 +657,7 @@ static void LaplacianDeformModifier_do( sys = static_cast(lmd->cache_system); if (sysdif) { if (ELEM(sysdif, LAPDEFORM_SYSTEM_ONLY_CHANGE_ANCHORS, LAPDEFORM_SYSTEM_ONLY_CHANGE_GROUP)) { - filevertexCos = static_cast( - MEM_malloc_arrayN(verts_num, sizeof(float[3]), __func__)); + filevertexCos = MEM_malloc_arrayN(size_t(verts_num), __func__); memcpy(filevertexCos, lmd->vertexco, sizeof(float[3]) * verts_num); MEM_SAFE_FREE(lmd->vertexco); lmd->verts_num = 0; @@ -703,8 +701,7 @@ static void LaplacianDeformModifier_do( lmd->flag &= ~MOD_LAPLACIANDEFORM_BIND; } else if (lmd->verts_num > 0 && lmd->verts_num == verts_num) { - filevertexCos = static_cast( - MEM_malloc_arrayN(verts_num, sizeof(float[3]), "TempDeformCoordinates")); + filevertexCos = MEM_malloc_arrayN(size_t(verts_num), "TempDeformCoordinates"); memcpy(filevertexCos, lmd->vertexco, sizeof(float[3]) * verts_num); MEM_SAFE_FREE(lmd->vertexco); lmd->verts_num = 0; diff --git a/source/blender/modifiers/intern/MOD_meshcache.cc b/source/blender/modifiers/intern/MOD_meshcache.cc index df7f7e3ce15..833a82f8ecf 100644 --- a/source/blender/modifiers/intern/MOD_meshcache.cc +++ b/source/blender/modifiers/intern/MOD_meshcache.cc @@ -81,8 +81,7 @@ static void meshcache_do(MeshCacheModifierData *mcmd, float(*vertexCos_Store)[3] = (use_factor || influence_group_index != -1 || (mcmd->deform_mode == MOD_MESHCACHE_DEFORM_INTEGRATE)) ? - static_cast(MEM_malloc_arrayN( - verts_num, sizeof(*vertexCos_Store), __func__)) : + MEM_malloc_arrayN(size_t(verts_num), __func__) : nullptr; float(*vertexCos)[3] = vertexCos_Store ? vertexCos_Store : vertexCos_Real; @@ -173,8 +172,7 @@ static void meshcache_do(MeshCacheModifierData *mcmd, BKE_modifier_set_error(ob, &mcmd->modifier, "'Integrate' requires faces"); } else { - float(*vertexCos_New)[3] = static_cast( - MEM_malloc_arrayN(verts_num, sizeof(*vertexCos_New), __func__)); + float(*vertexCos_New)[3] = MEM_malloc_arrayN(size_t(verts_num), __func__); BKE_mesh_calc_relative_deform( mesh->face_offsets().data(), diff --git a/source/blender/modifiers/intern/MOD_meshdeform.cc b/source/blender/modifiers/intern/MOD_meshdeform.cc index 833665cd3ba..b163ef0afc4 100644 --- a/source/blender/modifiers/intern/MOD_meshdeform.cc +++ b/source/blender/modifiers/intern/MOD_meshdeform.cc @@ -464,9 +464,8 @@ void BKE_modifier_mdef_compact_influences(ModifierData *md) } /* allocate bind influences */ - mmd->bindinfluences = static_cast( - MEM_calloc_arrayN(mmd->influences_num, sizeof(MDefInfluence), __func__)); - mmd->bindoffsets = static_cast(MEM_calloc_arrayN((verts_num + 1), sizeof(int), __func__)); + mmd->bindinfluences = MEM_calloc_arrayN(size_t(mmd->influences_num), __func__); + mmd->bindoffsets = MEM_calloc_arrayN(size_t(verts_num) + 1, __func__); /* write influences */ influences_num = 0; diff --git a/source/blender/modifiers/intern/MOD_multires.cc b/source/blender/modifiers/intern/MOD_multires.cc index 7797b936a78..7894311ff21 100644 --- a/source/blender/modifiers/intern/MOD_multires.cc +++ b/source/blender/modifiers/intern/MOD_multires.cc @@ -87,8 +87,7 @@ static MultiresRuntimeData *multires_ensure_runtime(MultiresModifierData *mmd) { MultiresRuntimeData *runtime_data = (MultiresRuntimeData *)mmd->modifier.runtime; if (runtime_data == nullptr) { - runtime_data = static_cast( - MEM_callocN(sizeof(*runtime_data), __func__)); + runtime_data = MEM_callocN(__func__); mmd->modifier.runtime = runtime_data; } return runtime_data; diff --git a/source/blender/modifiers/intern/MOD_normal_edit.cc b/source/blender/modifiers/intern/MOD_normal_edit.cc index 1da47f2779e..4128bf6817f 100644 --- a/source/blender/modifiers/intern/MOD_normal_edit.cc +++ b/source/blender/modifiers/intern/MOD_normal_edit.cc @@ -134,8 +134,7 @@ static void mix_normals(const float mix_factor, int i; if (dvert) { - facs = static_cast( - MEM_malloc_arrayN(size_t(corner_verts.size()), sizeof(*facs), __func__)); + facs = MEM_malloc_arrayN(size_t(corner_verts.size()), __func__); BKE_defvert_extract_vgroup_to_loopweights(dvert, defgrp_index, verts_num, @@ -233,8 +232,7 @@ static void normalEditModifier_do_radial(NormalEditModifierData *enmd, const bool do_facenors_fix = (enmd->flag & MOD_NORMALEDIT_NO_POLYNORS_FIX) == 0; - float(*cos)[3] = static_cast( - MEM_malloc_arrayN(size_t(vert_positions.size()), sizeof(*cos), __func__)); + float(*cos)[3] = MEM_malloc_arrayN(size_t(vert_positions.size()), __func__); blender::Array nos(corner_verts.size()); float3 size; @@ -384,8 +382,7 @@ static void normalEditModifier_do_directional(NormalEditModifierData *enmd, } } else { - float(*cos)[3] = static_cast( - MEM_malloc_arrayN(size_t(positions.size()), sizeof(*cos), __func__)); + float(*cos)[3] = MEM_malloc_arrayN(size_t(positions.size()), __func__); generate_vert_coordinates(mesh, ob, ob_target, nullptr, positions.size(), cos, nullptr); BLI_bitmap *done_verts = BLI_BITMAP_NEW(size_t(positions.size()), __func__); diff --git a/source/blender/modifiers/intern/MOD_particleinstance.cc b/source/blender/modifiers/intern/MOD_particleinstance.cc index 802166bb1e3..ea617b3b3d2 100644 --- a/source/blender/modifiers/intern/MOD_particleinstance.cc +++ b/source/blender/modifiers/intern/MOD_particleinstance.cc @@ -244,7 +244,7 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh if (pimd->flag & eParticleInstanceFlag_UseSize) { float *si; - si = size = static_cast(MEM_calloc_arrayN(part_end, sizeof(float), __func__)); + si = size = MEM_calloc_arrayN(part_end, __func__); if (pimd->flag & eParticleInstanceFlag_Parents) { for (p = 0, pa = psys->particles; p < psys->totpart; p++, pa++, si++) { diff --git a/source/blender/modifiers/intern/MOD_screw.cc b/source/blender/modifiers/intern/MOD_screw.cc index 9627dea2af7..907a765de57 100644 --- a/source/blender/modifiers/intern/MOD_screw.cc +++ b/source/blender/modifiers/intern/MOD_screw.cc @@ -157,7 +157,7 @@ static Mesh *mesh_remove_doubles_on_axis(Mesh *result, if (tot_doubles != 0) { uint tot = totvert * step_tot; - int *full_doubles_map = static_cast(MEM_malloc_arrayN(tot, sizeof(int), __func__)); + int *full_doubles_map = MEM_malloc_arrayN(tot, __func__); copy_vn_i(full_doubles_map, int(tot), -1); uint tot_doubles_left = tot_doubles; @@ -461,12 +461,10 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh /* build face -> edge map */ if (faces_num) { - edge_face_map = static_cast( - MEM_malloc_arrayN(totedge, sizeof(*edge_face_map), __func__)); + edge_face_map = MEM_malloc_arrayN(totedge, __func__); memset(edge_face_map, 0xff, sizeof(*edge_face_map) * totedge); - vert_loop_map = static_cast( - MEM_malloc_arrayN(totvert, sizeof(*vert_loop_map), __func__)); + vert_loop_map = MEM_malloc_arrayN(totvert, __func__); memset(vert_loop_map, 0xff, sizeof(*vert_loop_map) * totvert); for (const int64_t i : faces_orig.index_range()) { @@ -490,8 +488,7 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * Sort edge verts for correct face flipping * NOT REALLY NEEDED but face flipping is nice. */ - vert_connect = static_cast( - MEM_malloc_arrayN(totvert, sizeof(ScrewVertConnect), __func__)); + vert_connect = MEM_malloc_arrayN(totvert, __func__); /* skip the first slice of verts. */ // vert_connect = (ScrewVertConnect *) &medge_new[totvert]; vc = vert_connect; diff --git a/source/blender/modifiers/intern/MOD_smooth.cc b/source/blender/modifiers/intern/MOD_smooth.cc index c8708c76fc3..bdb2a4e8bac 100644 --- a/source/blender/modifiers/intern/MOD_smooth.cc +++ b/source/blender/modifiers/intern/MOD_smooth.cc @@ -69,14 +69,12 @@ static void smoothModifier_do( return; } - float(*accumulated_vecs)[3] = static_cast( - MEM_calloc_arrayN(size_t(verts_num), sizeof(*accumulated_vecs), __func__)); + float(*accumulated_vecs)[3] = MEM_calloc_arrayN(size_t(verts_num), __func__); if (!accumulated_vecs) { return; } - uint *accumulated_vecs_count = static_cast( - MEM_calloc_arrayN(size_t(verts_num), sizeof(*accumulated_vecs_count), __func__)); + uint *accumulated_vecs_count = MEM_calloc_arrayN(size_t(verts_num), __func__); if (!accumulated_vecs_count) { MEM_freeN(accumulated_vecs); return; diff --git a/source/blender/modifiers/intern/MOD_solidify_extrude.cc b/source/blender/modifiers/intern/MOD_solidify_extrude.cc index 6213d0b79bc..29ba4469372 100644 --- a/source/blender/modifiers/intern/MOD_solidify_extrude.cc +++ b/source/blender/modifiers/intern/MOD_solidify_extrude.cc @@ -230,13 +230,11 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex #define INVALID_UNUSED uint(-1) #define INVALID_PAIR uint(-2) - new_vert_arr = static_cast( - MEM_malloc_arrayN(verts_num, 2 * sizeof(*new_vert_arr), __func__)); - new_edge_arr = static_cast( - MEM_malloc_arrayN(((edges_num * 2) + verts_num), sizeof(*new_edge_arr), __func__)); + new_vert_arr = MEM_malloc_arrayN(2 * verts_num, __func__); + new_edge_arr = MEM_malloc_arrayN(((edges_num * 2) + verts_num), __func__); - edge_users = static_cast(MEM_malloc_arrayN(edges_num, sizeof(*edge_users), __func__)); - edge_order = static_cast(MEM_malloc_arrayN(edges_num, sizeof(*edge_order), __func__)); + edge_users = MEM_malloc_arrayN(edges_num, __func__); + edge_order = MEM_malloc_arrayN(edges_num, __func__); /* save doing 2 loops here... */ #if 0 @@ -314,7 +312,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex #endif if (smd->flag & MOD_SOLIDIFY_NORMAL_CALC) { - vert_nors = static_cast(MEM_calloc_arrayN(verts_num, sizeof(float[3]), __func__)); + vert_nors = MEM_calloc_arrayN(verts_num, __func__); mesh_calc_hq_normal(mesh, face_normals, vert_nors @@ -495,7 +493,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex float *edge_angs = nullptr; if (do_clamp) { - vert_lens = static_cast(MEM_malloc_arrayN(verts_num, sizeof(float), "vert_lens")); + vert_lens = MEM_malloc_arrayN(verts_num, "vert_lens"); copy_vn_fl(vert_lens, int(verts_num), FLT_MAX); for (uint i = 0; i < edges_num; i++) { const float ed_len_sq = len_squared_v3v3(vert_positions[edges[i][0]], @@ -508,18 +506,16 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex if (do_angle_clamp || do_bevel_convex) { uint eidx; if (do_angle_clamp) { - vert_angs = static_cast(MEM_malloc_arrayN(verts_num, sizeof(float), "vert_angs")); + vert_angs = MEM_malloc_arrayN(verts_num, "vert_angs"); copy_vn_fl(vert_angs, int(verts_num), 0.5f * M_PI); } if (do_bevel_convex) { - edge_angs = static_cast(MEM_malloc_arrayN(edges_num, sizeof(float), "edge_angs")); + edge_angs = MEM_malloc_arrayN(edges_num, "edge_angs"); if (!do_rim) { - edge_users = static_cast( - MEM_malloc_arrayN(edges_num, sizeof(*edge_users), "solid_mod edges")); + edge_users = MEM_malloc_arrayN(edges_num, "solid_mod edges"); } } - uint(*edge_user_pairs)[2] = static_cast( - MEM_malloc_arrayN(edges_num, sizeof(*edge_user_pairs), "edge_user_pairs")); + uint(*edge_user_pairs)[2] = MEM_malloc_arrayN(edges_num, "edge_user_pairs"); for (eidx = 0; eidx < edges_num; eidx++) { edge_user_pairs[eidx][0] = INVALID_UNUSED; edge_user_pairs[eidx][1] = INVALID_UNUSED; @@ -711,15 +707,13 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex const bool check_non_manifold = (smd->flag & MOD_SOLIDIFY_NORMAL_CALC) != 0; #endif /* same as EM_solidify() in editmesh_lib.c */ - float *vert_angles = static_cast( - MEM_calloc_arrayN(verts_num, sizeof(float[2]), "mod_solid_pair")); /* 2 in 1 */ + float *vert_angles = MEM_calloc_arrayN(2 * verts_num, "mod_solid_pair"); /* 2 in 1 */ float *vert_accum = vert_angles + verts_num; uint vidx; uint i; if (vert_nors == nullptr) { - vert_nors = static_cast( - MEM_malloc_arrayN(verts_num, sizeof(float[3]), "mod_solid_vno")); + vert_nors = MEM_malloc_arrayN(verts_num, "mod_solid_vno"); for (i = 0; i < verts_num; i++) { copy_v3_v3(vert_nors[i], vert_normals[i]); } @@ -808,20 +802,16 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex if (do_angle_clamp || do_bevel_convex) { uint eidx; if (do_angle_clamp) { - vert_angs = static_cast( - MEM_malloc_arrayN(verts_num, sizeof(float), "vert_angs even")); + vert_angs = MEM_malloc_arrayN(verts_num, "vert_angs even"); copy_vn_fl(vert_angs, int(verts_num), 0.5f * M_PI); } if (do_bevel_convex) { - edge_angs = static_cast( - MEM_malloc_arrayN(edges_num, sizeof(float), "edge_angs even")); + edge_angs = MEM_malloc_arrayN(edges_num, "edge_angs even"); if (!do_rim) { - edge_users = static_cast( - MEM_malloc_arrayN(edges_num, sizeof(*edge_users), "solid_mod edges")); + edge_users = MEM_malloc_arrayN(edges_num, "solid_mod edges"); } } - uint(*edge_user_pairs)[2] = static_cast( - MEM_malloc_arrayN(edges_num, sizeof(*edge_user_pairs), "edge_user_pairs")); + uint(*edge_user_pairs)[2] = MEM_malloc_arrayN(edges_num, "edge_user_pairs"); for (eidx = 0; eidx < edges_num; eidx++) { edge_user_pairs[eidx][0] = INVALID_UNUSED; edge_user_pairs[eidx][1] = INVALID_UNUSED; @@ -879,8 +869,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex const float clamp_fac = 1 + (do_angle_clamp ? fabsf(smd->offset_fac) : 0); const float offset = fabsf(smd->offset) * smd->offset_clamp * clamp_fac; if (offset > FLT_EPSILON) { - float *vert_lens_sq = static_cast( - MEM_malloc_arrayN(verts_num, sizeof(float), "vert_lens_sq")); + float *vert_lens_sq = MEM_malloc_arrayN(verts_num, "vert_lens_sq"); const float offset_sq = offset * offset; copy_vn_fl(vert_lens_sq, int(verts_num), FLT_MAX); for (i = 0; i < edges_num; i++) { diff --git a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.cc b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.cc index f59351624ef..d3916ae44be 100644 --- a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.cc +++ b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.cc @@ -212,10 +212,10 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, blender::Array face_nors = mesh->face_normals(); blender::Array face_sides_arr(faces_num * 2); - bool *null_faces = - (smd->nonmanifold_offset_mode == MOD_SOLIDIFY_NONMANIFOLD_OFFSET_MODE_CONSTRAINTS) ? - static_cast(MEM_calloc_arrayN(faces_num, sizeof(*null_faces), __func__)) : - nullptr; + bool *null_faces = (smd->nonmanifold_offset_mode == + MOD_SOLIDIFY_NONMANIFOLD_OFFSET_MODE_CONSTRAINTS) ? + MEM_calloc_arrayN(faces_num, __func__) : + nullptr; uint largest_ngon = 3; /* Calculate face to #NewFaceRef map. */ { @@ -237,8 +237,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, } } - NewEdgeRef **link_edges = static_cast( - MEM_calloc_arrayN(uint(face.size()), sizeof(*link_edges), __func__)); + NewEdgeRef **link_edges = MEM_calloc_arrayN(uint(face.size()), __func__); NewFaceRef new_face_ref_a{}; new_face_ref_a.face = face; @@ -247,8 +246,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, new_face_ref_a.link_edges = link_edges; face_sides_arr[i * 2] = std::move(new_face_ref_a); - link_edges = static_cast( - MEM_calloc_arrayN(uint(face.size()), sizeof(*link_edges), __func__)); + link_edges = MEM_calloc_arrayN(uint(face.size()), __func__); NewFaceRef new_face_ref_b{}; new_face_ref_b.face = face; @@ -268,8 +266,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, } } - uint *edge_adj_faces_len = static_cast( - MEM_calloc_arrayN(edges_num, sizeof(*edge_adj_faces_len), __func__)); + uint *edge_adj_faces_len = MEM_calloc_arrayN(edges_num, __func__); /* Count for each edge how many faces it has adjacent. */ { for (const int64_t i : orig_faces.index_range()) { @@ -280,16 +277,13 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, } /* Original edge to #NewEdgeRef map. */ - NewEdgeRef ***orig_edge_data_arr = static_cast( - MEM_calloc_arrayN(edges_num, sizeof(*orig_edge_data_arr), __func__)); + NewEdgeRef ***orig_edge_data_arr = MEM_calloc_arrayN(edges_num, __func__); /* Original edge length cache. */ - float *orig_edge_lengths = static_cast( - MEM_calloc_arrayN(edges_num, sizeof(*orig_edge_lengths), __func__)); + float *orig_edge_lengths = MEM_calloc_arrayN(edges_num, __func__); /* Edge groups for every original vert. */ - EdgeGroup **orig_vert_groups_arr = static_cast( - MEM_calloc_arrayN(verts_num, sizeof(*orig_vert_groups_arr), __func__)); + EdgeGroup **orig_vert_groups_arr = MEM_calloc_arrayN(verts_num, __func__); /* vertex map used to map duplicates. */ - uint *vm = static_cast(MEM_malloc_arrayN(verts_num, sizeof(*vm), __func__)); + uint *vm = MEM_malloc_arrayN(verts_num, __func__); for (uint i = 0; i < verts_num; i++) { vm[i] = i; } @@ -301,11 +295,9 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, bool has_singularities = false; /* Vert edge adjacent map. */ - OldVertEdgeRef **vert_adj_edges = static_cast( - MEM_calloc_arrayN(verts_num, sizeof(*vert_adj_edges), __func__)); + OldVertEdgeRef **vert_adj_edges = MEM_calloc_arrayN(verts_num, __func__); /* Original vertex positions (changed for degenerated geometry). */ - float(*orig_mvert_co)[3] = static_cast( - MEM_malloc_arrayN(verts_num, sizeof(*orig_mvert_co), __func__)); + float(*orig_mvert_co)[3] = MEM_malloc_arrayN(verts_num, __func__); /* Fill in the original vertex positions. */ for (uint i = 0; i < verts_num; i++) { orig_mvert_co[i][0] = orig_vert_positions[i][0]; @@ -315,8 +307,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, /* Create edge to #NewEdgeRef map. */ { - OldEdgeFaceRef **edge_adj_faces = static_cast( - MEM_calloc_arrayN(edges_num, sizeof(*edge_adj_faces), __func__)); + OldEdgeFaceRef **edge_adj_faces = MEM_calloc_arrayN(edges_num, __func__); /* Create link_faces for edges. */ { @@ -329,17 +320,14 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, if (old_face_edge_ref == nullptr) { const uint len = edge_adj_faces_len[edge]; BLI_assert(len > 0); - uint *adj_faces = static_cast( - MEM_malloc_arrayN(len, sizeof(*adj_faces), __func__)); - bool *adj_faces_reversed = static_cast( - MEM_malloc_arrayN(len, sizeof(*adj_faces_reversed), __func__)); + uint *adj_faces = MEM_malloc_arrayN(len, __func__); + bool *adj_faces_reversed = MEM_malloc_arrayN(len, __func__); adj_faces[0] = uint(i); for (uint k = 1; k < len; k++) { adj_faces[k] = MOD_SOLIDIFY_EMPTY_TAG; } adj_faces_reversed[0] = reversed; - OldEdgeFaceRef *ref = static_cast( - MEM_mallocN(sizeof(*ref), __func__)); + OldEdgeFaceRef *ref = MEM_mallocN(__func__); *ref = OldEdgeFaceRef{adj_faces, len, adj_faces_reversed, 1}; edge_adj_faces[edge] = ref; } @@ -357,17 +345,14 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, } float edgedir[3] = {0, 0, 0}; - uint *vert_adj_edges_len = static_cast( - MEM_calloc_arrayN(verts_num, sizeof(*vert_adj_edges_len), __func__)); + uint *vert_adj_edges_len = MEM_calloc_arrayN(verts_num, __func__); /* Calculate edge lengths and len vert_adj edges. */ { - bool *face_singularity = static_cast( - MEM_calloc_arrayN(faces_num, sizeof(*face_singularity), __func__)); + bool *face_singularity = MEM_calloc_arrayN(faces_num, __func__); const float merge_tolerance_sqr = smd->merge_tolerance * smd->merge_tolerance; - uint *combined_verts = static_cast( - MEM_calloc_arrayN(verts_num, sizeof(*combined_verts), __func__)); + uint *combined_verts = MEM_calloc_arrayN(verts_num, __func__); for (uint i = 0; i < edges_num; i++) { const int2 &edge = orig_edges[i]; @@ -502,14 +487,12 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, if (len > 0) { OldVertEdgeRef *old_edge_vert_ref = vert_adj_edges[vert]; if (old_edge_vert_ref == nullptr) { - uint *adj_edges = static_cast( - MEM_calloc_arrayN(len, sizeof(*adj_edges), __func__)); + uint *adj_edges = MEM_calloc_arrayN(len, __func__); adj_edges[0] = i; for (uint k = 1; k < len; k++) { adj_edges[k] = MOD_SOLIDIFY_EMPTY_TAG; } - OldVertEdgeRef *ref = static_cast( - MEM_mallocN(sizeof(*ref), __func__)); + OldVertEdgeRef *ref = MEM_mallocN(__func__); *ref = OldVertEdgeRef{adj_edges, 1}; vert_adj_edges[vert] = ref; } @@ -568,10 +551,8 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, new_loops_num -= 4 * j; } const uint len = i_adj_faces->faces_len + invalid_adj_faces->faces_len - 2 * j; - uint *adj_faces = static_cast( - MEM_malloc_arrayN(len, sizeof(*adj_faces), __func__)); - bool *adj_faces_loops_reversed = static_cast( - MEM_malloc_arrayN(len, sizeof(*adj_faces_loops_reversed), __func__)); + uint *adj_faces = MEM_malloc_arrayN(len, __func__); + bool *adj_faces_loops_reversed = MEM_malloc_arrayN(len, __func__); /* Clean merge of adj_faces. */ j = 0; for (uint k = 0; k < i_adj_faces->faces_len; k++) { @@ -778,8 +759,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, const uint *adj_faces_faces = adj_faces->faces; const bool *adj_faces_reversed = adj_faces->faces_reversed; uint new_edges_len = 0; - FaceKeyPair *sorted_faces = static_cast( - MEM_malloc_arrayN(adj_len, sizeof(*sorted_faces), __func__)); + FaceKeyPair *sorted_faces = MEM_malloc_arrayN(adj_len, __func__); if (adj_len > 1) { new_edges_len = adj_len; /* Get keys for sorting. */ @@ -834,8 +814,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, } /* Create a list of new edges and fill it. */ - NewEdgeRef **new_edges = static_cast( - MEM_malloc_arrayN(new_edges_len + 1, sizeof(*new_edges), __func__)); + NewEdgeRef **new_edges = MEM_malloc_arrayN(new_edges_len + 1, __func__); new_edges[new_edges_len] = nullptr; NewFaceRef *faces[2]; for (uint j = 0; j < new_edges_len; j++) { @@ -856,8 +835,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, faces[1] = nullptr; angle = 0; } - NewEdgeRef *edge_data = static_cast( - MEM_mallocN(sizeof(*edge_data), __func__)); + NewEdgeRef *edge_data = MEM_mallocN(__func__); uint edge_data_edge_index = MOD_SOLIDIFY_EMPTY_TAG; if (do_shell || (adj_len == 1 && do_rim)) { edge_data_edge_index = 0; @@ -942,8 +920,8 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, } } } - NewEdgeRef **unassigned_edges = static_cast( - MEM_malloc_arrayN(unassigned_edges_len, sizeof(*unassigned_edges), __func__)); + NewEdgeRef **unassigned_edges = MEM_malloc_arrayN(unassigned_edges_len, + __func__); for (uint j = 0, k = 0; j < tot_adj_edges; j++) { NewEdgeRef **new_edges = orig_edge_data_arr[adj_edges[j]]; if (new_edges) { @@ -957,8 +935,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, /* An edge group will always contain min 2 edges * so max edge group count can be calculated. */ uint edge_groups_len = unassigned_edges_len / 2; - edge_groups = static_cast( - MEM_calloc_arrayN(edge_groups_len + 1, sizeof(*edge_groups), __func__)); + edge_groups = MEM_calloc_arrayN(edge_groups_len + 1, __func__); uint assigned_edges_len = 0; NewEdgeRef *found_edge = nullptr; @@ -1064,8 +1041,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, const uint needed_capacity = edge_groups[eg_index].edges_len + 1; if (needed_capacity > eg_capacity) { eg_capacity = needed_capacity + 1; - NewEdgeRef **new_eg = static_cast( - MEM_calloc_arrayN(eg_capacity, sizeof(*new_eg), __func__)); + NewEdgeRef **new_eg = MEM_calloc_arrayN(eg_capacity, __func__); if (insert_at_start) { memcpy(new_eg + 1, edge_groups[eg_index].edges, @@ -1102,8 +1078,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, eg_index++; BLI_assert(eg_index < edge_groups_len); eg_capacity = 5; - NewEdgeRef **edges = static_cast( - MEM_calloc_arrayN(eg_capacity, sizeof(*edges), __func__)); + NewEdgeRef **edges = MEM_calloc_arrayN(eg_capacity, __func__); EdgeGroup edge_group{}; edge_group.valid = true; @@ -1144,8 +1119,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, const uint edges_len = edge_groups[j + add_index].edges_len; if (edges_len > 3) { bool has_doubles = false; - bool *doubles = static_cast( - MEM_calloc_arrayN(edges_len, sizeof(*doubles), __func__)); + bool *doubles = MEM_calloc_arrayN(edges_len, __func__); EdgeGroup g = edge_groups[j + add_index]; for (uint k = 0; k < edges_len; k++) { for (uint l = k + 1; l < edges_len; l++) { @@ -1193,8 +1167,8 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, } if (last_split > split) { const uint edges_len_group = (split + edges_len) - uint(last_split); - NewEdgeRef **edges = static_cast( - MEM_malloc_arrayN(edges_len_group, sizeof(*edges), __func__)); + NewEdgeRef **edges = MEM_malloc_arrayN(edges_len_group, + __func__); memcpy(edges, g.edges + last_split, (edges_len - uint(last_split)) * sizeof(*edges)); @@ -1219,8 +1193,8 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, } else { const uint edges_len_group = split - uint(last_split); - NewEdgeRef **edges = static_cast( - MEM_malloc_arrayN(edges_len_group, sizeof(*edges), __func__)); + NewEdgeRef **edges = MEM_malloc_arrayN(edges_len_group, + __func__); memcpy(edges, g.edges + last_split, edges_len_group * sizeof(*edges)); EdgeGroup edge_group{}; @@ -1266,8 +1240,8 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, edge_groups + (j + add_index + 1), (uint(eg_index) - j - 1) * sizeof(*edge_groups)); } - NewEdgeRef **edges = static_cast( - MEM_malloc_arrayN(uint(first_split), sizeof(*edges), __func__)); + NewEdgeRef **edges = MEM_malloc_arrayN(uint(first_split), + __func__); memcpy(edges, g.edges, uint(first_split) * sizeof(*edges)); EdgeGroup edge_group_a{}; @@ -1287,8 +1261,8 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, add_index++; splits++; - edges = static_cast(MEM_malloc_arrayN( - edges_len - uint(last_split), sizeof(*edges), __func__)); + edges = MEM_malloc_arrayN(edges_len - uint(last_split), + __func__); memcpy(edges, g.edges + last_split, (edges_len - uint(last_split)) * sizeof(*edges)); @@ -1413,8 +1387,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, float *face_weight = nullptr; if (do_flat_faces) { - face_weight = static_cast( - MEM_malloc_arrayN(faces_num, sizeof(*face_weight), __func__)); + face_weight = MEM_malloc_arrayN(faces_num, __func__); for (const int i : orig_faces.index_range()) { float scalar_vgroup = 1.0f; @@ -1453,8 +1426,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, NewEdgeRef *first_edge = nullptr; NewEdgeRef **edge_ptr = g->edges; /* Contains normal and offset `[nx, ny, nz, ofs]`. */ - float(*planes_queue)[4] = static_cast( - MEM_malloc_arrayN(g->edges_len + 1, sizeof(*planes_queue), __func__)); + float(*planes_queue)[4] = MEM_malloc_arrayN(g->edges_len + 1, __func__); uint queue_index = 0; float fallback_nor[3]; @@ -1947,8 +1919,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, has_singularities = false; uint i = 0; uint singularity_edges_len = 1; - singularity_edges = static_cast( - MEM_malloc_arrayN(singularity_edges_len, sizeof(*singularity_edges), __func__)); + singularity_edges = MEM_malloc_arrayN(singularity_edges_len, __func__); for (NewEdgeRef ***new_edges = orig_edge_data_arr; i < edges_num; i++, new_edges++) { if (*new_edges && (do_shell || edge_adj_faces_len[i] == 1) && (**new_edges)->old_edge == i) { for (NewEdgeRef **l = *new_edges; *l; l++) { @@ -2286,8 +2257,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, edge_index++; /* Loop data. */ - int *loops_data = static_cast( - MEM_malloc_arrayN(j, sizeof(*loops_data), __func__)); + int *loops_data = MEM_malloc_arrayN(j, __func__); /* The result material index is from consensus. */ short most_mat_nr = 0; uint most_mat_nr_face = 0; @@ -2556,12 +2526,9 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, /* Make faces. */ if (do_shell) { - uint *face_loops = static_cast( - MEM_malloc_arrayN(largest_ngon * 2, sizeof(*face_loops), __func__)); - uint *face_verts = static_cast( - MEM_malloc_arrayN(largest_ngon * 2, sizeof(*face_verts), __func__)); - uint *face_edges = static_cast( - MEM_malloc_arrayN(largest_ngon * 2, sizeof(*face_edges), __func__)); + uint *face_loops = MEM_malloc_arrayN(largest_ngon * 2, __func__); + uint *face_verts = MEM_malloc_arrayN(largest_ngon * 2, __func__); + uint *face_edges = MEM_malloc_arrayN(largest_ngon * 2, __func__); for (uint i = 0; i < faces_num * 2; i++) { NewFaceRef &fr = face_sides_arr[i]; const uint loopstart = uint(fr.face.start()); diff --git a/source/blender/modifiers/intern/MOD_surface.cc b/source/blender/modifiers/intern/MOD_surface.cc index bea0dd8b167..72f256508e3 100644 --- a/source/blender/modifiers/intern/MOD_surface.cc +++ b/source/blender/modifiers/intern/MOD_surface.cc @@ -121,10 +121,8 @@ static void deform_verts(ModifierData *md, MEM_SAFE_FREE(surmd->runtime.vert_positions_prev); MEM_SAFE_FREE(surmd->runtime.vert_velocities); - surmd->runtime.vert_positions_prev = static_cast( - MEM_calloc_arrayN(mesh_verts_num, sizeof(float[3]), __func__)); - surmd->runtime.vert_velocities = static_cast( - MEM_calloc_arrayN(mesh_verts_num, sizeof(float[3]), __func__)); + surmd->runtime.vert_positions_prev = MEM_calloc_arrayN(mesh_verts_num, __func__); + surmd->runtime.vert_velocities = MEM_calloc_arrayN(mesh_verts_num, __func__); surmd->runtime.verts_num = mesh_verts_num; diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.cc b/source/blender/modifiers/intern/MOD_surfacedeform.cc index 71c8f53fcdb..bc20a8aea33 100644 --- a/source/blender/modifiers/intern/MOD_surfacedeform.cc +++ b/source/blender/modifiers/intern/MOD_surfacedeform.cc @@ -488,7 +488,7 @@ BLI_INLINE SDefBindWeightData *computeBindWeights(SDefBindCalcData *const data, float tot_weight = 0.0f; int inf_weight_flags = 0; - bwdata = static_cast(MEM_callocN(sizeof(*bwdata), "SDefBindWeightData")); + bwdata = MEM_callocN("SDefBindWeightData"); if (bwdata == nullptr) { data->success = MOD_SDEF_BIND_RESULT_MEM_ERR; return nullptr; @@ -496,8 +496,7 @@ BLI_INLINE SDefBindWeightData *computeBindWeights(SDefBindCalcData *const data, bwdata->faces_num = data->vert_edges[nearest].num / 2; - bpoly = static_cast( - MEM_calloc_arrayN(bwdata->faces_num, sizeof(*bpoly), "SDefBindPoly")); + bpoly = MEM_calloc_arrayN(size_t(bwdata->faces_num), "SDefBindPoly"); if (bpoly == nullptr) { freeBindData(bwdata); data->success = MOD_SDEF_BIND_RESULT_MEM_ERR; @@ -540,16 +539,15 @@ BLI_INLINE SDefBindWeightData *computeBindWeights(SDefBindCalcData *const data, bpoly->verts_num = face.size(); bpoly->loopstart = face.start(); - bpoly->coords = static_cast( - MEM_malloc_arrayN(face.size(), sizeof(*bpoly->coords), "SDefBindPolyCoords")); + bpoly->coords = MEM_malloc_arrayN(size_t(face.size()), "SDefBindPolyCoords"); if (bpoly->coords == nullptr) { freeBindData(bwdata); data->success = MOD_SDEF_BIND_RESULT_MEM_ERR; return nullptr; } - bpoly->coords_v2 = static_cast( - MEM_malloc_arrayN(face.size(), sizeof(*bpoly->coords_v2), "SDefBindPolyCoords_v2")); + bpoly->coords_v2 = MEM_malloc_arrayN(size_t(face.size()), + "SDefBindPolyCoords_v2"); if (bpoly->coords_v2 == nullptr) { freeBindData(bwdata); data->success = MOD_SDEF_BIND_RESULT_MEM_ERR; @@ -989,8 +987,7 @@ static void bindVert(void *__restrict userdata, return; } - sdvert->binds = static_cast( - MEM_calloc_arrayN(bwdata->binds_num, sizeof(*sdvert->binds), "SDefVertBindData")); + sdvert->binds = MEM_calloc_arrayN(size_t(bwdata->binds_num), "SDefVertBindData"); if (sdvert->binds == nullptr) { data->success = MOD_SDEF_BIND_RESULT_MEM_ERR; sdvert->binds_num = 0; @@ -1010,15 +1007,14 @@ static void bindVert(void *__restrict userdata, sdbind->verts_num = bpoly->verts_num; sdbind->mode = MOD_SDEF_MODE_NGONS; - sdbind->vert_weights = static_cast(MEM_malloc_arrayN( - bpoly->verts_num, sizeof(*sdbind->vert_weights), "SDefNgonVertWeights")); + sdbind->vert_weights = MEM_malloc_arrayN(size_t(bpoly->verts_num), + "SDefNgonVertWeights"); if (sdbind->vert_weights == nullptr) { data->success = MOD_SDEF_BIND_RESULT_MEM_ERR; return; } - sdbind->vert_inds = static_cast( - MEM_malloc_arrayN(bpoly->verts_num, sizeof(*sdbind->vert_inds), "SDefNgonVertInds")); + sdbind->vert_inds = MEM_malloc_arrayN(size_t(bpoly->verts_num), "SDefNgonVertInds"); if (sdbind->vert_inds == nullptr) { data->success = MOD_SDEF_BIND_RESULT_MEM_ERR; return; @@ -1051,15 +1047,14 @@ static void bindVert(void *__restrict userdata, sdbind->verts_num = bpoly->verts_num; sdbind->mode = MOD_SDEF_MODE_CENTROID; - sdbind->vert_weights = static_cast( - MEM_malloc_arrayN(3, sizeof(*sdbind->vert_weights), "SDefCentVertWeights")); + sdbind->vert_weights = MEM_malloc_arrayN(3, "SDefCentVertWeights"); if (sdbind->vert_weights == nullptr) { data->success = MOD_SDEF_BIND_RESULT_MEM_ERR; return; } - sdbind->vert_inds = static_cast( - MEM_malloc_arrayN(bpoly->verts_num, sizeof(*sdbind->vert_inds), "SDefCentVertInds")); + sdbind->vert_inds = MEM_malloc_arrayN(size_t(bpoly->verts_num), + "SDefCentVertInds"); if (sdbind->vert_inds == nullptr) { data->success = MOD_SDEF_BIND_RESULT_MEM_ERR; return; @@ -1099,15 +1094,13 @@ static void bindVert(void *__restrict userdata, sdbind->verts_num = bpoly->verts_num; sdbind->mode = MOD_SDEF_MODE_CORNER_TRIS; - sdbind->vert_weights = static_cast( - MEM_malloc_arrayN(3, sizeof(*sdbind->vert_weights), "SDefTriVertWeights")); + sdbind->vert_weights = MEM_malloc_arrayN(3, "SDefTriVertWeights"); if (sdbind->vert_weights == nullptr) { data->success = MOD_SDEF_BIND_RESULT_MEM_ERR; return; } - sdbind->vert_inds = static_cast( - MEM_malloc_arrayN(bpoly->verts_num, sizeof(*sdbind->vert_inds), "SDefTriVertInds")); + sdbind->vert_inds = MEM_malloc_arrayN(size_t(bpoly->verts_num), "SDefTriVertInds"); if (sdbind->vert_inds == nullptr) { data->success = MOD_SDEF_BIND_RESULT_MEM_ERR; return; @@ -1180,23 +1173,23 @@ static bool surfacedeformBind(Object *ob, uint tedges_num = target->edges_num; int adj_result; - SDefAdjacencyArray *vert_edges = static_cast( - MEM_calloc_arrayN(target_verts_num, sizeof(*vert_edges), "SDefVertEdgeMap")); + SDefAdjacencyArray *vert_edges = MEM_calloc_arrayN(size_t(target_verts_num), + "SDefVertEdgeMap"); if (vert_edges == nullptr) { BKE_modifier_set_error(ob, (ModifierData *)smd_eval, "Out of memory"); return false; } - SDefAdjacency *adj_array = static_cast( - MEM_malloc_arrayN(tedges_num, 2 * sizeof(*adj_array), "SDefVertEdge")); + SDefAdjacency *adj_array = MEM_malloc_arrayN(2 * size_t(tedges_num), + "SDefVertEdge"); if (adj_array == nullptr) { BKE_modifier_set_error(ob, (ModifierData *)smd_eval, "Out of memory"); MEM_freeN(vert_edges); return false; } - SDefEdgePolys *edge_polys = static_cast( - MEM_calloc_arrayN(tedges_num, sizeof(*edge_polys), "SDefEdgeFaceMap")); + SDefEdgePolys *edge_polys = MEM_calloc_arrayN(size_t(tedges_num), + "SDefEdgeFaceMap"); if (edge_polys == nullptr) { BKE_modifier_set_error(ob, (ModifierData *)smd_eval, "Out of memory"); MEM_freeN(vert_edges); @@ -1204,8 +1197,7 @@ static bool surfacedeformBind(Object *ob, return false; } - smd_orig->verts = static_cast( - MEM_malloc_arrayN(verts_num, sizeof(*smd_orig->verts), "SDefBindVerts")); + smd_orig->verts = MEM_malloc_arrayN(size_t(verts_num), "SDefBindVerts"); if (smd_orig->verts == nullptr) { BKE_modifier_set_error(ob, (ModifierData *)smd_eval, "Out of memory"); freeAdjacencyMap(vert_edges, adj_array, edge_polys); @@ -1252,8 +1244,8 @@ static bool surfacedeformBind(Object *ob, data.corner_edges = corner_edges; data.corner_tris = target->corner_tris(); data.tri_faces = target->corner_tri_faces(); - data.targetCos = static_cast( - MEM_malloc_arrayN(target_verts_num, sizeof(float[3]), "SDefTargetBindVertArray")); + data.targetCos = MEM_malloc_arrayN(size_t(target_verts_num), + "SDefTargetBindVertArray"); data.bind_verts = smd_orig->verts; data.vertexCos = vertexCos; data.falloff = smd_orig->falloff; @@ -1537,8 +1529,7 @@ static void surfacedeformModifier_do(ModifierData *md, /* Actual vertex location update starts here */ SDefDeformData data{}; data.bind_verts = smd->verts; - data.targetCos = static_cast( - MEM_malloc_arrayN(target_verts_num, sizeof(float[3]), "SDefTargetVertArray")); + data.targetCos = MEM_malloc_arrayN(size_t(target_verts_num), "SDefTargetVertArray"); data.vertexCos = vertexCos; data.dvert = dvert; data.defgrp_index = defgrp_index; diff --git a/source/blender/modifiers/intern/MOD_warp.cc b/source/blender/modifiers/intern/MOD_warp.cc index d972ea5c5c3..869be9b8a26 100644 --- a/source/blender/modifiers/intern/MOD_warp.cc +++ b/source/blender/modifiers/intern/MOD_warp.cc @@ -234,7 +234,7 @@ static void warpModifier_do(WarpModifierData *wmd, Tex *tex_target = wmd->texture; if (mesh != nullptr && tex_target != nullptr) { - tex_co = static_cast(MEM_malloc_arrayN(verts_num, sizeof(*tex_co), __func__)); + tex_co = MEM_malloc_arrayN(size_t(verts_num), __func__); MOD_get_texture_coords((MappingInfoModifierData *)wmd, ctx, ob, mesh, vertexCos, tex_co); MOD_init_texture((MappingInfoModifierData *)wmd, ctx); diff --git a/source/blender/modifiers/intern/MOD_wave.cc b/source/blender/modifiers/intern/MOD_wave.cc index 22cb48c5dc4..3403b3ec7ef 100644 --- a/source/blender/modifiers/intern/MOD_wave.cc +++ b/source/blender/modifiers/intern/MOD_wave.cc @@ -170,7 +170,7 @@ static void waveModifier_do(WaveModifierData *wmd, Tex *tex_target = wmd->texture; if (mesh != nullptr && tex_target != nullptr) { - tex_co = static_cast(MEM_malloc_arrayN(verts_num, sizeof(*tex_co), __func__)); + tex_co = MEM_malloc_arrayN(size_t(verts_num), __func__); MOD_get_texture_coords((MappingInfoModifierData *)wmd, ctx, ob, mesh, vertexCos, tex_co); MOD_init_texture((MappingInfoModifierData *)wmd, ctx); diff --git a/source/blender/modifiers/intern/MOD_weighted_normal.cc b/source/blender/modifiers/intern/MOD_weighted_normal.cc index 3f39f511b09..2e19fd8d811 100644 --- a/source/blender/modifiers/intern/MOD_weighted_normal.cc +++ b/source/blender/modifiers/intern/MOD_weighted_normal.cc @@ -381,8 +381,7 @@ static void wn_face_area(WeightedNormalModifierData *wnmd, WeightedNormalData *w const blender::OffsetIndices faces = wn_data->faces; const blender::Span corner_verts = wn_data->corner_verts; - ModePair *face_area = static_cast( - MEM_malloc_arrayN(faces.size(), sizeof(*face_area), __func__)); + ModePair *face_area = MEM_malloc_arrayN(size_t(faces.size()), __func__); ModePair *f_area = face_area; for (const int i : faces.index_range()) { @@ -402,13 +401,11 @@ static void wn_corner_angle(WeightedNormalModifierData *wnmd, WeightedNormalData const blender::OffsetIndices faces = wn_data->faces; const blender::Span corner_verts = wn_data->corner_verts; - ModePair *corner_angle = static_cast( - MEM_malloc_arrayN(corner_verts.size(), sizeof(*corner_angle), __func__)); + ModePair *corner_angle = MEM_malloc_arrayN(size_t(corner_verts.size()), __func__); for (const int i : faces.index_range()) { const blender::IndexRange face = faces[i]; - float *index_angle = static_cast( - MEM_malloc_arrayN(face.size(), sizeof(*index_angle), __func__)); + float *index_angle = MEM_malloc_arrayN(size_t(face.size()), __func__); blender::bke::mesh::face_angles_calc( positions, corner_verts.slice(face), {index_angle, face.size()}); @@ -435,15 +432,13 @@ static void wn_face_with_angle(WeightedNormalModifierData *wnmd, WeightedNormalD const blender::OffsetIndices faces = wn_data->faces; const blender::Span corner_verts = wn_data->corner_verts; - ModePair *combined = static_cast( - MEM_malloc_arrayN(corner_verts.size(), sizeof(*combined), __func__)); + ModePair *combined = MEM_malloc_arrayN(size_t(corner_verts.size()), __func__); for (const int i : faces.index_range()) { const blender::IndexRange face = faces[i]; const blender::Span face_verts = corner_verts.slice(face); const float face_area = blender::bke::mesh::face_area_calc(positions, face_verts); - float *index_angle = static_cast( - MEM_malloc_arrayN(size_t(face.size()), sizeof(*index_angle), __func__)); + float *index_angle = MEM_malloc_arrayN(size_t(face.size()), __func__); blender::bke::mesh::face_angles_calc(positions, face_verts, {index_angle, face.size()}); ModePair *cmbnd = &combined[face.start()]; diff --git a/source/blender/modifiers/intern/MOD_weightvg_util.cc b/source/blender/modifiers/intern/MOD_weightvg_util.cc index 1ffcdc52bf6..d3b9fdae6fb 100644 --- a/source/blender/modifiers/intern/MOD_weightvg_util.cc +++ b/source/blender/modifiers/intern/MOD_weightvg_util.cc @@ -149,7 +149,7 @@ void weightvg_do_mask(const ModifierEvalContext *ctx, STRNCPY(t_map.uvlayer_name, tex_uvlayer_name); t_map.texmapping = tex_mapping; - tex_co = static_cast(MEM_calloc_arrayN(verts_num, sizeof(*tex_co), __func__)); + tex_co = MEM_calloc_arrayN(size_t(verts_num), __func__); MOD_get_texture_coords(&t_map, ctx, ob, mesh, nullptr, tex_co); MOD_init_texture(&t_map, ctx); diff --git a/source/blender/modifiers/intern/MOD_weightvgedit.cc b/source/blender/modifiers/intern/MOD_weightvgedit.cc index fbfb32f068b..531f8ac13f8 100644 --- a/source/blender/modifiers/intern/MOD_weightvgedit.cc +++ b/source/blender/modifiers/intern/MOD_weightvgedit.cc @@ -202,10 +202,9 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh } /* Get org weights, assuming 0.0 for vertices not in given vgroup. */ - org_w = static_cast(MEM_malloc_arrayN(verts_num, sizeof(float), __func__)); - new_w = static_cast(MEM_malloc_arrayN(verts_num, sizeof(float), __func__)); - dw = static_cast( - MEM_malloc_arrayN(verts_num, sizeof(MDeformWeight *), __func__)); + org_w = MEM_malloc_arrayN(size_t(verts_num), __func__); + new_w = MEM_malloc_arrayN(size_t(verts_num), __func__); + dw = MEM_malloc_arrayN(size_t(verts_num), __func__); for (i = 0; i < verts_num; i++) { dw[i] = BKE_defvert_find_index(&dvert[i], defgrp_index); if (dw[i]) { diff --git a/source/blender/modifiers/intern/MOD_weightvgmix.cc b/source/blender/modifiers/intern/MOD_weightvgmix.cc index c23cf3e6d8c..24f7a6bb4e5 100644 --- a/source/blender/modifiers/intern/MOD_weightvgmix.cc +++ b/source/blender/modifiers/intern/MOD_weightvgmix.cc @@ -267,11 +267,9 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh } /* Find out which vertices to work on. */ - tidx = static_cast(MEM_malloc_arrayN(verts_num, sizeof(int), __func__)); - tdw1 = static_cast( - MEM_malloc_arrayN(verts_num, sizeof(MDeformWeight *), __func__)); - tdw2 = static_cast( - MEM_malloc_arrayN(verts_num, sizeof(MDeformWeight *), __func__)); + tidx = MEM_malloc_arrayN(size_t(verts_num), __func__); + tdw1 = MEM_malloc_arrayN(size_t(verts_num), __func__); + tdw2 = MEM_malloc_arrayN(size_t(verts_num), __func__); switch (wmd->mix_set) { case MOD_WVG_SET_A: /* All vertices in first vgroup. */ @@ -347,14 +345,12 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh return mesh; } if (index_num != -1) { - indices = static_cast(MEM_malloc_arrayN(index_num, sizeof(int), __func__)); + indices = MEM_malloc_arrayN(size_t(index_num), __func__); memcpy(indices, tidx, sizeof(int) * index_num); - dw1 = static_cast( - MEM_malloc_arrayN(index_num, sizeof(MDeformWeight *), __func__)); + dw1 = MEM_malloc_arrayN(size_t(index_num), __func__); memcpy(dw1, tdw1, sizeof(MDeformWeight *) * index_num); MEM_freeN(tdw1); - dw2 = static_cast( - MEM_malloc_arrayN(index_num, sizeof(MDeformWeight *), __func__)); + dw2 = MEM_malloc_arrayN(size_t(index_num), __func__); memcpy(dw2, tdw2, sizeof(MDeformWeight *) * index_num); MEM_freeN(tdw2); } @@ -367,8 +363,8 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh } MEM_freeN(tidx); - org_w = static_cast(MEM_malloc_arrayN(index_num, sizeof(float), __func__)); - new_w = static_cast(MEM_malloc_arrayN(index_num, sizeof(float), __func__)); + org_w = MEM_malloc_arrayN(size_t(index_num), __func__); + new_w = MEM_malloc_arrayN(size_t(index_num), __func__); /* Mix weights. */ for (i = 0; i < index_num; i++) { diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.cc b/source/blender/modifiers/intern/MOD_weightvgproximity.cc index f2ab54b49e8..64e907b22cc 100644 --- a/source/blender/modifiers/intern/MOD_weightvgproximity.cc +++ b/source/blender/modifiers/intern/MOD_weightvgproximity.cc @@ -473,10 +473,9 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh } /* Find out which vertices to work on (all vertices in vgroup), and get their relevant weight. */ - tidx = static_cast(MEM_malloc_arrayN(verts_num, sizeof(int), __func__)); - tw = static_cast(MEM_malloc_arrayN(verts_num, sizeof(float), __func__)); - tdw = static_cast( - MEM_malloc_arrayN(verts_num, sizeof(MDeformWeight *), __func__)); + tidx = MEM_malloc_arrayN(size_t(verts_num), __func__); + tw = MEM_malloc_arrayN(size_t(verts_num), __func__); + tdw = MEM_malloc_arrayN(size_t(verts_num), __func__); for (i = 0; i < verts_num; i++) { MDeformWeight *_dw = BKE_defvert_find_index(&dvert[i], defgrp_index); if (_dw) { @@ -493,12 +492,11 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh return mesh; } if (index_num != verts_num) { - indices = static_cast(MEM_malloc_arrayN(index_num, sizeof(int), __func__)); + indices = MEM_malloc_arrayN(size_t(index_num), __func__); memcpy(indices, tidx, sizeof(int) * index_num); - org_w = static_cast(MEM_malloc_arrayN(index_num, sizeof(float), __func__)); + org_w = MEM_malloc_arrayN(size_t(index_num), __func__); memcpy(org_w, tw, sizeof(float) * index_num); - dw = static_cast( - MEM_malloc_arrayN(index_num, sizeof(MDeformWeight *), __func__)); + dw = MEM_malloc_arrayN(size_t(index_num), __func__); memcpy(dw, tdw, sizeof(MDeformWeight *) * index_num); MEM_freeN(tw); MEM_freeN(tdw); @@ -507,7 +505,7 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh org_w = tw; dw = tdw; } - new_w = static_cast(MEM_malloc_arrayN(index_num, sizeof(float), __func__)); + new_w = MEM_malloc_arrayN(size_t(index_num), __func__); MEM_freeN(tidx); const blender::Span positions = mesh->vert_positions(); @@ -535,14 +533,11 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh BKE_mesh_wrapper_ensure_mdata(target_mesh); SpaceTransform loc2trgt; - float *dists_v = use_trgt_verts ? static_cast(MEM_malloc_arrayN( - index_num, sizeof(float), __func__)) : + float *dists_v = use_trgt_verts ? MEM_malloc_arrayN(size_t(index_num), __func__) : nullptr; - float *dists_e = use_trgt_edges ? static_cast(MEM_malloc_arrayN( - index_num, sizeof(float), __func__)) : + float *dists_e = use_trgt_edges ? MEM_malloc_arrayN(size_t(index_num), __func__) : nullptr; - float *dists_f = use_trgt_faces ? static_cast(MEM_malloc_arrayN( - index_num, sizeof(float), __func__)) : + float *dists_f = use_trgt_faces ? MEM_malloc_arrayN(size_t(index_num), __func__) : nullptr; BLI_SPACE_TRANSFORM_SETUP(&loc2trgt, ob, obr); diff --git a/source/blender/modifiers/intern/lineart/lineart_cpu.cc b/source/blender/modifiers/intern/lineart/lineart_cpu.cc index 237865a1ed2..98f59b5be4b 100644 --- a/source/blender/modifiers/intern/lineart/lineart_cpu.cc +++ b/source/blender/modifiers/intern/lineart/lineart_cpu.cc @@ -376,8 +376,7 @@ static void lineart_bounding_area_line_add(LineartBoundingArea *ba, LineartEdge return; } if (ba->line_count >= ba->max_line_count) { - LineartEdge **new_array = static_cast( - MEM_malloc_arrayN(ba->max_line_count * 2, sizeof(LineartEdge *), __func__)); + LineartEdge **new_array = MEM_malloc_arrayN(ba->max_line_count * 2, __func__); memcpy(new_array, ba->linked_lines, sizeof(LineartEdge *) * ba->max_line_count); ba->max_line_count *= 2; MEM_freeN(ba->linked_lines); @@ -472,8 +471,8 @@ static void lineart_occlusion_worker(TaskPool *__restrict /*pool*/, LineartRende void lineart_main_occlusion_begin(LineartData *ld) { int thread_count = ld->thread_count; - LineartRenderTaskInfo *rti = static_cast( - MEM_callocN(sizeof(LineartRenderTaskInfo) * thread_count, __func__)); + LineartRenderTaskInfo *rti = MEM_calloc_arrayN(size_t(thread_count), + __func__); int i; TaskPool *tp = BLI_task_pool_create(nullptr, TASK_PRIORITY_HIGH); @@ -1742,8 +1741,8 @@ void lineart_add_edge_to_array(LineartPendingEdges *pe, LineartEdge *e) pe->max = 1000; } - LineartEdge **new_array = static_cast( - MEM_mallocN(sizeof(LineartEdge *) * pe->max * 2, "LineartPendingEdges array")); + LineartEdge **new_array = MEM_malloc_arrayN(size_t(pe->max) * 2, + "LineartPendingEdges array"); if (LIKELY(pe->array)) { memcpy(new_array, pe->array, sizeof(LineartEdge *) * pe->max); MEM_freeN(pe->array); @@ -1769,8 +1768,8 @@ void lineart_finalize_object_edge_array_reserve(LineartPendingEdges *pe, int cou } pe->max = count; - LineartEdge **new_array = static_cast( - MEM_mallocN(sizeof(LineartEdge *) * pe->max, "LineartPendingEdges array final")); + LineartEdge **new_array = MEM_malloc_arrayN(size_t(pe->max), + "LineartPendingEdges array final"); pe->array = new_array; } @@ -1933,10 +1932,10 @@ static void lineart_sort_adjacent_items(LineartAdjacentEdge *ai, int length) static LineartEdgeNeighbor *lineart_build_edge_neighbor(Mesh *mesh, int total_edges) { /* Because the mesh is triangulated, so `mesh->edges_num` should be reliable? */ - LineartAdjacentEdge *adj_e = static_cast( - MEM_mallocN(sizeof(LineartAdjacentEdge) * total_edges, "LineartAdjacentEdge arr")); - LineartEdgeNeighbor *edge_nabr = static_cast( - MEM_mallocN(sizeof(LineartEdgeNeighbor) * total_edges, "LineartEdgeNeighbor arr")); + LineartAdjacentEdge *adj_e = MEM_malloc_arrayN(size_t(total_edges), + "LineartAdjacentEdge arr"); + LineartEdgeNeighbor *edge_nabr = MEM_malloc_arrayN( + size_t(total_edges), "LineartEdgeNeighbor arr"); TaskParallelSettings en_settings; BLI_parallel_range_settings_defaults(&en_settings); @@ -2049,8 +2048,8 @@ static void lineart_geometry_object_load(LineartObjectInfo *ob_info, ((usage == OBJECT_LRT_NO_INTERSECTION) ? LRT_ELEMENT_NO_INTERSECTION : 0)); /* Note this memory is not from pool, will be deleted after culling. */ - LineartTriangleAdjacent *tri_adj = static_cast(MEM_callocN( - sizeof(LineartTriangleAdjacent) * corner_tris.size(), "LineartTriangleAdjacent")); + LineartTriangleAdjacent *tri_adj = MEM_calloc_arrayN( + size_t(corner_tris.size()), "LineartTriangleAdjacent"); /* Link is minimal so we use pool anyway. */ BLI_spin_lock(&la_data->lock_task); lineart_list_append_pointer_pool_thread( @@ -2153,8 +2152,7 @@ static void lineart_geometry_object_load(LineartObjectInfo *ob_info, /* Only identifying floating edges at this point because other edges has been taken care of * inside #lineart_identify_corner_tri_feature_edges function. */ const LooseEdgeCache &loose_edges = mesh->loose_edges(); - loose_data.loose_array = static_cast( - MEM_malloc_arrayN(loose_edges.count, sizeof(int), __func__)); + loose_data.loose_array = MEM_malloc_arrayN(size_t(loose_edges.count), __func__); if (loose_edges.count > 0) { loose_data.loose_count = 0; for (const int64_t edge_i : IndexRange(mesh->edges_num)) { @@ -3319,8 +3317,8 @@ static void lineart_add_isec_thread(LineartIsecThread *th, { if (th->current == th->max) { - LineartIsecSingle *new_array = static_cast( - MEM_mallocN(sizeof(LineartIsecSingle) * th->max * 2, "LineartIsecSingle")); + LineartIsecSingle *new_array = MEM_malloc_arrayN(size_t(th->max) * 2, + "LineartIsecSingle"); memcpy(new_array, th->array, sizeof(LineartIsecSingle) * th->max); th->max *= 2; MEM_freeN(th->array); @@ -3386,8 +3384,7 @@ static bool lineart_schedule_new_triangle_task(LineartIsecThread *th) */ static void lineart_init_isec_thread(LineartIsecData *d, LineartData *ld, int thread_count) { - d->threads = static_cast( - MEM_callocN(sizeof(LineartIsecThread) * thread_count, "LineartIsecThread arr")); + d->threads = MEM_calloc_arrayN(size_t(thread_count), "LineartIsecThread arr"); d->ld = ld; d->thread_count = thread_count; @@ -3397,8 +3394,7 @@ static void lineart_init_isec_thread(LineartIsecData *d, LineartData *ld, int th for (int i = 0; i < thread_count; i++) { LineartIsecThread *it = &d->threads[i]; - it->array = static_cast( - MEM_mallocN(sizeof(LineartIsecSingle) * 100, "LineartIsecSingle arr")); + it->array = MEM_malloc_arrayN(100, "LineartIsecSingle arr"); it->max = 100; it->current = 0; it->thread_id = i; @@ -3570,8 +3566,7 @@ void MOD_lineart_destroy_render_data_v3(GreasePencilLineartModifierData *lmd) LineartCache *MOD_lineart_init_cache() { - LineartCache *lc = static_cast( - MEM_callocN(sizeof(LineartCache), "Lineart Cache")); + LineartCache *lc = MEM_callocN("Lineart Cache"); return lc; } @@ -3591,8 +3586,7 @@ static LineartData *lineart_create_render_buffer_v3(Scene *scene, Object *active_camera, LineartCache *lc) { - LineartData *ld = static_cast( - MEM_callocN(sizeof(LineartData), "Line Art render buffer")); + LineartData *ld = MEM_callocN("Line Art render buffer"); lmd->cache = lc; lmd->la_data_ptr = ld; lc->all_enabled_edge_types = lmd->edge_types_override; @@ -3793,10 +3787,9 @@ void lineart_main_bounding_area_make_initial(LineartData *ld) /* Init linked_triangles array. */ ba->max_triangle_count = LRT_TILE_SPLITTING_TRIANGLE_LIMIT; ba->max_line_count = LRT_TILE_EDGE_COUNT_INITIAL; - ba->linked_triangles = static_cast( - MEM_callocN(sizeof(LineartTriangle *) * ba->max_triangle_count, "ba_linked_triangles")); - ba->linked_lines = static_cast( - MEM_callocN(sizeof(LineartEdge *) * ba->max_line_count, "ba_linked_lines")); + ba->linked_triangles = MEM_calloc_arrayN(ba->max_triangle_count, + "ba_linked_triangles"); + ba->linked_lines = MEM_calloc_arrayN(ba->max_line_count, "ba_linked_lines"); BLI_spin_init(&ba->lock); } @@ -4038,10 +4031,9 @@ static void lineart_bounding_area_split(LineartData *ld, for (int i = 0; i < 4; i++) { ba[i].max_triangle_count = LRT_TILE_SPLITTING_TRIANGLE_LIMIT; ba[i].max_line_count = LRT_TILE_EDGE_COUNT_INITIAL; - ba[i].linked_triangles = static_cast( - MEM_callocN(sizeof(LineartTriangle *) * ba[i].max_triangle_count, "ba_linked_triangles")); - ba[i].linked_lines = static_cast( - MEM_callocN(sizeof(LineartEdge *) * ba[i].max_line_count, "ba_linked_lines")); + ba[i].linked_triangles = MEM_calloc_arrayN(ba[i].max_triangle_count, + "ba_linked_triangles"); + ba[i].linked_lines = MEM_calloc_arrayN(ba[i].max_line_count, "ba_linked_lines"); BLI_spin_init(&ba[i].lock); } @@ -4334,8 +4326,8 @@ static void lineart_clear_linked_edges_recursive(LineartData *ld, LineartBoundin } root_ba->line_count = 0; root_ba->max_line_count = 128; - root_ba->linked_lines = static_cast( - MEM_callocN(sizeof(LineartEdge *) * root_ba->max_line_count, "cleared lineart edges")); + root_ba->linked_lines = MEM_calloc_arrayN(root_ba->max_line_count, + "cleared lineart edges"); } void lineart_main_clear_linked_edges(LineartData *ld) { @@ -4392,8 +4384,8 @@ static void lineart_main_remove_unused_lines_recursive(LineartBoundingArea *ba, return; } - LineartEdge **new_array = static_cast( - MEM_callocN(sizeof(LineartEdge *) * usable_count, "cleaned lineart edge array")); + LineartEdge **new_array = MEM_calloc_arrayN(size_t(usable_count), + "cleaned lineart edge array"); int new_i = 0; for (int i = 0; i < ba->line_count; i++) { diff --git a/source/blender/modifiers/intern/lineart/lineart_shadow.cc b/source/blender/modifiers/intern/lineart/lineart_shadow.cc index d38b481e982..8e591a0112b 100644 --- a/source/blender/modifiers/intern/lineart/lineart_shadow.cc +++ b/source/blender/modifiers/intern/lineart/lineart_shadow.cc @@ -1173,8 +1173,7 @@ bool lineart_main_try_generate_shadow_v3(Depsgraph *depsgraph, } } - LineartData *ld = static_cast( - MEM_mallocN(sizeof(LineartData), "LineArt render buffer copied")); + LineartData *ld = MEM_mallocN("LineArt render buffer copied"); memcpy(ld, original_ld, sizeof(LineartData)); BLI_spin_init(&ld->lock_task);