diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-01-18 02:58:54 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-01-18 03:01:17 +0300 |
commit | 27dff3fbc1e74aa6613d68a0d9f9b0096fc86f6e (patch) | |
tree | 91c4fb3bbe944a4f9e0e6d72a25d12310872f849 /source/blender/modifiers/intern | |
parent | 8400b4b566350bd9d726a07627e74f5a995280da (diff) | |
parent | e6df02861e17f75d4dd243776f35208681b78465 (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'source/blender/modifiers/intern')
31 files changed, 139 insertions, 139 deletions
diff --git a/source/blender/modifiers/intern/MOD_array.c b/source/blender/modifiers/intern/MOD_array.c index cd19020d375..91501e539c0 100644 --- a/source/blender/modifiers/intern/MOD_array.c +++ b/source/blender/modifiers/intern/MOD_array.c @@ -177,8 +177,8 @@ static void dm_mvert_map_doubles( source_end = source_start + source_num_verts; /* build array of MVerts to be tested for merging */ - sorted_verts_target = MEM_mallocN(sizeof(SortVertsElem) * target_num_verts, __func__); - sorted_verts_source = MEM_mallocN(sizeof(SortVertsElem) * source_num_verts, __func__); + sorted_verts_target = MEM_malloc_arrayN(target_num_verts, sizeof(SortVertsElem), __func__); + sorted_verts_source = MEM_malloc_arrayN(source_num_verts, sizeof(SortVertsElem), __func__); /* Copy target vertices index and cos into SortVertsElem array */ svert_from_mvert(sorted_verts_target, mverts + target_start, target_start, target_end); @@ -491,7 +491,7 @@ static DerivedMesh *arrayModifier_doArray( if (use_merge) { /* Will need full_doubles_map for handling merge */ - full_doubles_map = MEM_mallocN(sizeof(int) * result_nverts, "mod array doubles map"); + full_doubles_map = MEM_malloc_arrayN(result_nverts, sizeof(int), "mod array doubles map"); copy_vn_i(full_doubles_map, result_nverts, -1); } diff --git a/source/blender/modifiers/intern/MOD_boolean.c b/source/blender/modifiers/intern/MOD_boolean.c index 5811017f745..0554fbb0317 100644 --- a/source/blender/modifiers/intern/MOD_boolean.c +++ b/source/blender/modifiers/intern/MOD_boolean.c @@ -239,7 +239,7 @@ static DerivedMesh *applyModifier_bmesh( int tottri; BMLoop *(*looptris)[3]; - looptris = MEM_mallocN(sizeof(*looptris) * looptris_tot, __func__); + looptris = MEM_malloc_arrayN(looptris_tot, sizeof(*looptris), __func__); BM_mesh_calc_tessellation_beauty(bm, looptris, &tottri); diff --git a/source/blender/modifiers/intern/MOD_build.c b/source/blender/modifiers/intern/MOD_build.c index 0a0ad11fe16..7a52ede8838 100644 --- a/source/blender/modifiers/intern/MOD_build.c +++ b/source/blender/modifiers/intern/MOD_build.c @@ -104,9 +104,9 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte MVert *mvert_src = dm->getVertArray(dm); - vertMap = MEM_mallocN(sizeof(*vertMap) * numVert_src, "build modifier vertMap"); - edgeMap = MEM_mallocN(sizeof(*edgeMap) * numEdge_src, "build modifier edgeMap"); - faceMap = MEM_mallocN(sizeof(*faceMap) * numPoly_src, "build modifier faceMap"); + vertMap = MEM_malloc_arrayN(numVert_src, sizeof(*vertMap), "build modifier vertMap"); + edgeMap = MEM_malloc_arrayN(numEdge_src, sizeof(*edgeMap), "build modifier edgeMap"); + faceMap = MEM_malloc_arrayN(numPoly_src, sizeof(*faceMap), "build modifier faceMap"); range_vn_i(vertMap, numVert_src, 0); range_vn_i(edgeMap, numEdge_src, 0); diff --git a/source/blender/modifiers/intern/MOD_collision.c b/source/blender/modifiers/intern/MOD_collision.c index b9a2310366a..d2ecbaeaafe 100644 --- a/source/blender/modifiers/intern/MOD_collision.c +++ b/source/blender/modifiers/intern/MOD_collision.c @@ -158,7 +158,7 @@ static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED { const MLoop *mloop = dm->getLoopArray(dm); const MLoopTri *looptri = dm->getLoopTriArray(dm); - MVertTri *tri = MEM_mallocN(sizeof(*tri) * collmd->tri_num, __func__); + MVertTri *tri = MEM_malloc_arrayN(collmd->tri_num, sizeof(*tri), __func__); DM_verttri_from_looptri(tri, mloop, looptri, collmd->tri_num); collmd->tri = tri; } diff --git a/source/blender/modifiers/intern/MOD_correctivesmooth.c b/source/blender/modifiers/intern/MOD_correctivesmooth.c index c43e4144f00..d95f0ae9286 100644 --- a/source/blender/modifiers/intern/MOD_correctivesmooth.c +++ b/source/blender/modifiers/intern/MOD_correctivesmooth.c @@ -156,7 +156,7 @@ static void dm_get_boundaries(DerivedMesh *dm, float *smooth_weights) mpoly_num = (unsigned int)dm->getNumPolys(dm); medge_num = (unsigned int)dm->getNumEdges(dm); - boundaries = MEM_callocN(medge_num * sizeof(*boundaries), __func__); + boundaries = MEM_calloc_arrayN(medge_num, sizeof(*boundaries), __func__); /* count the number of adjacent faces */ for (i = 0; i < mpoly_num; i++) { @@ -199,9 +199,9 @@ static void smooth_iter__simple( struct SmoothingData_Simple { float delta[3]; - } *smooth_data = MEM_callocN((size_t)numVerts * sizeof(*smooth_data), __func__); + } *smooth_data = MEM_calloc_arrayN(numVerts, sizeof(*smooth_data), __func__); - vertex_edge_count_div = MEM_callocN((size_t)numVerts * sizeof(float), __func__); + vertex_edge_count_div = MEM_calloc_arrayN(numVerts, sizeof(float), __func__); /* calculate as floats to avoid int->float conversion in #smooth_iter */ for (i = 0; i < numEdges; i++) { @@ -277,11 +277,11 @@ static void smooth_iter__length_weight( struct SmoothingData_Weighted { float delta[3]; float edge_length_sum; - } *smooth_data = MEM_callocN((size_t)numVerts * sizeof(*smooth_data), __func__); + } *smooth_data = MEM_calloc_arrayN(numVerts, sizeof(*smooth_data), __func__); /* calculate as floats to avoid int->float conversion in #smooth_iter */ - vertex_edge_count = MEM_callocN((size_t)numVerts * sizeof(float), __func__); + vertex_edge_count = MEM_calloc_arrayN(numVerts, sizeof(float), __func__); for (i = 0; i < numEdges; i++) { vertex_edge_count[edges[i].v1] += 1.0f; vertex_edge_count[edges[i].v2] += 1.0f; @@ -382,7 +382,7 @@ static void smooth_verts( if (dvert || (csmd->flag & MOD_CORRECTIVESMOOTH_PIN_BOUNDARY)) { - smooth_weights = MEM_mallocN(numVerts * sizeof(float), __func__); + smooth_weights = MEM_malloc_arrayN(numVerts, sizeof(float), __func__); if (dvert) { dm_get_weights( @@ -530,7 +530,7 @@ static void calc_deltas( float (*tangent_spaces)[3][3]; unsigned int i; - tangent_spaces = MEM_callocN((size_t)(numVerts) * sizeof(float[3][3]), __func__); + tangent_spaces = MEM_calloc_arrayN(numVerts, sizeof(float[3][3]), __func__); if (csmd->delta_cache_num != numVerts) { MEM_SAFE_FREE(csmd->delta_cache); @@ -539,7 +539,7 @@ static void calc_deltas( /* allocate deltas if they have not yet been allocated, otheriwse we will just write over them */ if (!csmd->delta_cache) { csmd->delta_cache_num = numVerts; - csmd->delta_cache = MEM_mallocN((size_t)numVerts * sizeof(float[3]), __func__); + csmd->delta_cache = MEM_malloc_arrayN(numVerts, sizeof(float[3]), __func__); } smooth_verts(csmd, dm, dvert, defgrp_index, smooth_vertex_coords, numVerts); @@ -680,7 +680,7 @@ static void correctivesmooth_modifier_do( float (*tangent_spaces)[3][3]; /* calloc, since values are accumulated */ - tangent_spaces = MEM_callocN((size_t)numVerts * sizeof(float[3][3]), __func__); + tangent_spaces = MEM_calloc_arrayN(numVerts, sizeof(float[3][3]), __func__); calc_tangent_spaces(dm, vertexCos, tangent_spaces); diff --git a/source/blender/modifiers/intern/MOD_decimate.c b/source/blender/modifiers/intern/MOD_decimate.c index 078a3085fc7..83dcd7b9b89 100644 --- a/source/blender/modifiers/intern/MOD_decimate.c +++ b/source/blender/modifiers/intern/MOD_decimate.c @@ -142,7 +142,7 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte const unsigned int vert_tot = dm->getNumVerts(dm); unsigned int i; - vweights = MEM_mallocN(vert_tot * sizeof(float), __func__); + vweights = MEM_malloc_arrayN(vert_tot, sizeof(float), __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.c b/source/blender/modifiers/intern/MOD_displace.c index 94a4ae9be17..53a77b6fe38 100644 --- a/source/blender/modifiers/intern/MOD_displace.c +++ b/source/blender/modifiers/intern/MOD_displace.c @@ -308,7 +308,7 @@ static void displaceModifier_do( modifier_get_vgroup(ob, dm, dmd->defgrp_name, &dvert, &defgrp_index); if (dmd->texture) { - tex_co = MEM_callocN(sizeof(*tex_co) * numVerts, + tex_co = MEM_calloc_arrayN((size_t)numVerts, sizeof(*tex_co), "displaceModifier_do tex_co"); get_texture_coords((MappingInfoModifierData *)dmd, ob, dm, vertexCos, tex_co, numVerts); @@ -329,7 +329,7 @@ static void displaceModifier_do( } clnors = CustomData_get_layer(ldata, CD_NORMAL); - vert_clnors = MEM_mallocN(sizeof(*vert_clnors) * (size_t)numVerts, __func__); + vert_clnors = MEM_malloc_arrayN(numVerts, sizeof(*vert_clnors), __func__); BKE_mesh_normals_loop_to_vertex(numVerts, dm->getLoopArray(dm), dm->getNumLoops(dm), (const float (*)[3])clnors, vert_clnors); } diff --git a/source/blender/modifiers/intern/MOD_explode.c b/source/blender/modifiers/intern/MOD_explode.c index 38785abbc19..8483da60576 100644 --- a/source/blender/modifiers/intern/MOD_explode.c +++ b/source/blender/modifiers/intern/MOD_explode.c @@ -119,9 +119,9 @@ static void createFacepa(ExplodeModifierData *emd, if (emd->facepa) MEM_freeN(emd->facepa); - facepa = emd->facepa = MEM_callocN(sizeof(int) * totface, "explode_facepa"); + facepa = emd->facepa = MEM_calloc_arrayN(totface, sizeof(int), "explode_facepa"); - vertpa = MEM_callocN(sizeof(int) * totvert, "explode_vertpa"); + vertpa = MEM_calloc_arrayN(totvert, sizeof(int), "explode_vertpa"); /* initialize all faces & verts to no particle */ for (i = 0; i < totface; i++) @@ -557,8 +557,8 @@ static DerivedMesh *cutEdges(ExplodeModifierData *emd, DerivedMesh *dm) int totvert = dm->getNumVerts(dm); int totface = dm->getNumTessFaces(dm); - int *facesplit = MEM_callocN(sizeof(int) * totface, "explode_facesplit"); - int *vertpa = MEM_callocN(sizeof(int) * totvert, "explode_vertpa2"); + int *facesplit = MEM_calloc_arrayN(totface, sizeof(int), "explode_facesplit"); + int *vertpa = MEM_calloc_arrayN(totvert, sizeof(int), "explode_vertpa2"); int *facepa = emd->facepa; int *fs, totesplit = 0, totfsplit = 0, curdupface = 0; int i, v1, v2, v3, v4, esplit, @@ -656,7 +656,7 @@ static DerivedMesh *cutEdges(ExplodeModifierData *emd, DerivedMesh *dm) * later interpreted as tri's, for this to work right I think we probably * have to stop using tessface - campbell */ - facepa = MEM_callocN(sizeof(int) * (totface + (totfsplit * 2)), "explode_facepa"); + facepa = MEM_calloc_arrayN((totface + (totfsplit * 2)), sizeof(int), "explode_facepa"); //memcpy(facepa, emd->facepa, totface*sizeof(int)); emd->facepa = facepa; diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c index 3684e947fe0..c9f475ad228 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim_util.c +++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c @@ -239,7 +239,7 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam return NULL; } - normals = MEM_callocN(sizeof(short) * numverts * 3, "fluid_tmp_normals"); + normals = MEM_calloc_arrayN(numverts, 3 * sizeof(short), "fluid_tmp_normals"); if (!normals) { if (dm) dm->release(dm); @@ -384,7 +384,7 @@ static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh * if (fss->domainNovecgen > 0) return; - fss->meshVelocities = MEM_callocN(sizeof(FluidVertexVelocity) * dm->getNumVerts(dm), "Fluidsim_velocities"); + fss->meshVelocities = MEM_calloc_arrayN(dm->getNumVerts(dm), sizeof(FluidVertexVelocity), "Fluidsim_velocities"); fss->totvert = totvert; velarray = fss->meshVelocities; diff --git a/source/blender/modifiers/intern/MOD_laplaciandeform.c b/source/blender/modifiers/intern/MOD_laplaciandeform.c index d322b8631d2..72db3f1c132 100644 --- a/source/blender/modifiers/intern/MOD_laplaciandeform.c +++ b/source/blender/modifiers/intern/MOD_laplaciandeform.c @@ -108,12 +108,12 @@ static LaplacianSystem *initLaplacianSystem( sys->total_anchors = totalAnchors; sys->repeat = iterations; BLI_strncpy(sys->anchor_grp_name, defgrpName, sizeof(sys->anchor_grp_name)); - sys->co = MEM_mallocN(sizeof(float[3]) * totalVerts, "DeformCoordinates"); - sys->no = MEM_callocN(sizeof(float[3]) * totalVerts, "DeformNormals"); - sys->delta = MEM_callocN(sizeof(float[3]) * totalVerts, "DeformDeltas"); - sys->tris = MEM_mallocN(sizeof(int[3]) * totalTris, "DeformFaces"); - sys->index_anchors = MEM_mallocN(sizeof(int) * (totalAnchors), "DeformAnchors"); - sys->unit_verts = MEM_callocN(sizeof(int) * totalVerts, "DeformUnitVerts"); + sys->co = MEM_malloc_arrayN(totalVerts, sizeof(float[3]), "DeformCoordinates"); + sys->no = MEM_calloc_arrayN(totalVerts, sizeof(float[3]), "DeformNormals"); + sys->delta = MEM_calloc_arrayN(totalVerts, sizeof(float[3]), "DeformDeltas"); + sys->tris = MEM_malloc_arrayN(totalTris, sizeof(int[3]), "DeformFaces"); + sys->index_anchors = MEM_malloc_arrayN((totalAnchors), sizeof(int), "DeformAnchors"); + sys->unit_verts = MEM_calloc_arrayN(totalVerts, sizeof(int), "DeformUnitVerts"); return sys; } @@ -142,7 +142,7 @@ static void createFaceRingMap( { int i, j, totalr = 0; int *indices, *index_iter; - MeshElemMap *map = MEM_callocN(sizeof(MeshElemMap) * mvert_tot, "DeformRingMap"); + MeshElemMap *map = MEM_calloc_arrayN(mvert_tot, sizeof(MeshElemMap), "DeformRingMap"); const MLoopTri *mlt; for (i = 0, mlt = mlooptri; i < mtri_tot; i++, mlt++) { @@ -153,7 +153,7 @@ static void createFaceRingMap( totalr++; } } - indices = MEM_callocN(sizeof(int) * totalr, "DeformRingIndex"); + indices = MEM_calloc_arrayN(totalr, sizeof(int), "DeformRingIndex"); index_iter = indices; for (i = 0; i < mvert_tot; i++) { map[i].indices = index_iter; @@ -175,7 +175,7 @@ static void createVertRingMap( const int mvert_tot, const MEdge *medge, const int medge_tot, MeshElemMap **r_map, int **r_indices) { - MeshElemMap *map = MEM_callocN(sizeof(MeshElemMap) * mvert_tot, "DeformNeighborsMap"); + MeshElemMap *map = MEM_calloc_arrayN(mvert_tot, sizeof(MeshElemMap), "DeformNeighborsMap"); int i, vid[2], totalr = 0; int *indices, *index_iter; const MEdge *me; @@ -187,7 +187,7 @@ static void createVertRingMap( map[vid[1]].count++; totalr += 2; } - indices = MEM_callocN(sizeof(int) * totalr, "DeformNeighborsIndex"); + indices = MEM_calloc_arrayN(totalr, sizeof(int), "DeformNeighborsIndex"); index_iter = indices; for (i = 0; i < mvert_tot; i++) { map[i].indices = index_iter; @@ -521,7 +521,7 @@ static void initSystem(LaplacianDeformModifierData *lmd, Object *ob, DerivedMesh LaplacianSystem *sys; if (isValidVertexGroup(lmd, ob, dm)) { - int *index_anchors = MEM_mallocN(sizeof(int) * numVerts, __func__); /* over-alloc */ + int *index_anchors = MEM_malloc_arrayN(numVerts, sizeof(int), __func__); /* over-alloc */ const MLoopTri *mlooptri; const MLoop *mloop; @@ -547,7 +547,7 @@ static void initSystem(LaplacianDeformModifierData *lmd, Object *ob, DerivedMesh memcpy(sys->index_anchors, index_anchors, sizeof(int) * total_anchors); memcpy(sys->co, vertexCos, sizeof(float[3]) * numVerts); MEM_freeN(index_anchors); - lmd->vertexco = MEM_mallocN(sizeof(float[3]) * numVerts, "ModDeformCoordinates"); + lmd->vertexco = MEM_malloc_arrayN(numVerts, sizeof(float[3]), "ModDeformCoordinates"); memcpy(lmd->vertexco, vertexCos, sizeof(float[3]) * numVerts); lmd->total_verts = numVerts; @@ -631,7 +631,7 @@ static void LaplacianDeformModifier_do( sys = lmd->cache_system; if (sysdif) { if (sysdif == LAPDEFORM_SYSTEM_ONLY_CHANGE_ANCHORS || sysdif == LAPDEFORM_SYSTEM_ONLY_CHANGE_GROUP) { - filevertexCos = MEM_mallocN(sizeof(float[3]) * numVerts, "TempModDeformCoordinates"); + filevertexCos = MEM_malloc_arrayN(numVerts, sizeof(float[3]), "TempModDeformCoordinates"); memcpy(filevertexCos, lmd->vertexco, sizeof(float[3]) * numVerts); MEM_SAFE_FREE(lmd->vertexco); lmd->total_verts = 0; @@ -667,7 +667,7 @@ static void LaplacianDeformModifier_do( lmd->flag &= ~MOD_LAPLACIANDEFORM_BIND; } else if (lmd->total_verts > 0 && lmd->total_verts == numVerts) { - filevertexCos = MEM_mallocN(sizeof(float[3]) * numVerts, "TempDeformCoordinates"); + filevertexCos = MEM_malloc_arrayN(numVerts, sizeof(float[3]), "TempDeformCoordinates"); memcpy(filevertexCos, lmd->vertexco, sizeof(float[3]) * numVerts); MEM_SAFE_FREE(lmd->vertexco); lmd->total_verts = 0; diff --git a/source/blender/modifiers/intern/MOD_laplaciansmooth.c b/source/blender/modifiers/intern/MOD_laplaciansmooth.c index d7bc7b6c427..977b8b41cc3 100644 --- a/source/blender/modifiers/intern/MOD_laplaciansmooth.c +++ b/source/blender/modifiers/intern/MOD_laplaciansmooth.c @@ -132,14 +132,14 @@ static LaplacianSystem *init_laplacian_system(int a_numEdges, int a_numPolys, in sys->numLoops = a_numLoops; sys->numVerts = a_numVerts; - sys->eweights = MEM_callocN(sizeof(float) * sys->numEdges, __func__); - sys->fweights = MEM_callocN(sizeof(float[3]) * sys->numLoops, __func__); - sys->numNeEd = MEM_callocN(sizeof(short) * sys->numVerts, __func__); - sys->numNeFa = MEM_callocN(sizeof(short) * sys->numVerts, __func__); - sys->ring_areas = MEM_callocN(sizeof(float) * sys->numVerts, __func__); - sys->vlengths = MEM_callocN(sizeof(float) * sys->numVerts, __func__); - sys->vweights = MEM_callocN(sizeof(float) * sys->numVerts, __func__); - sys->zerola = MEM_callocN(sizeof(short) * sys->numVerts, __func__); + sys->eweights = MEM_calloc_arrayN(sys->numEdges, sizeof(float), __func__); + sys->fweights = MEM_calloc_arrayN(sys->numLoops, sizeof(float[3]), __func__); + sys->numNeEd = MEM_calloc_arrayN(sys->numVerts, sizeof(short), __func__); + sys->numNeFa = MEM_calloc_arrayN(sys->numVerts, sizeof(short), __func__); + sys->ring_areas = MEM_calloc_arrayN(sys->numVerts, sizeof(float), __func__); + sys->vlengths = MEM_calloc_arrayN(sys->numVerts, sizeof(float), __func__); + sys->vweights = MEM_calloc_arrayN(sys->numVerts, sizeof(float), __func__); + sys->zerola = MEM_calloc_arrayN(sys->numVerts, sizeof(short), __func__); return sys; } diff --git a/source/blender/modifiers/intern/MOD_mask.c b/source/blender/modifiers/intern/MOD_mask.c index d942b23b216..bcebbc40adb 100644 --- a/source/blender/modifiers/intern/MOD_mask.c +++ b/source/blender/modifiers/intern/MOD_mask.c @@ -162,7 +162,7 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte * - each cell is a boolean saying whether bone corresponding to the ith group is selected * - groups that don't match a bone are treated as not existing (along with the corresponding ungrouped verts) */ - bone_select_array = MEM_mallocN((size_t)defbase_tot * sizeof(char), "mask array"); + bone_select_array = MEM_malloc_arrayN((size_t)defbase_tot, sizeof(char), "mask array"); for (i = 0, def = ob->defbase.first; def; def = def->next, i++) { pchan = BKE_pose_channel_find_name(oba->pose, def->name); @@ -246,7 +246,7 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte mloop_src = dm->getLoopArray(dm); /* overalloc, assume all polys are seen */ - loop_mapping = MEM_mallocN(sizeof(int) * (size_t)maxPolys, "mask loopmap"); + loop_mapping = MEM_malloc_arrayN((size_t)maxPolys, sizeof(int), "mask loopmap"); /* loop over edges and faces, and do the same thing to * ensure that they only reference existing verts diff --git a/source/blender/modifiers/intern/MOD_meshcache.c b/source/blender/modifiers/intern/MOD_meshcache.c index c990951c578..5dfa1d874b2 100644 --- a/source/blender/modifiers/intern/MOD_meshcache.c +++ b/source/blender/modifiers/intern/MOD_meshcache.c @@ -94,7 +94,7 @@ static void meshcache_do( { const bool use_factor = mcmd->factor < 1.0f; float (*vertexCos_Store)[3] = (use_factor || (mcmd->deform_mode == MOD_MESHCACHE_DEFORM_INTEGRATE)) ? - MEM_mallocN(sizeof(*vertexCos_Store) * numVerts, __func__) : NULL; + MEM_malloc_arrayN(numVerts, sizeof(*vertexCos_Store), __func__) : NULL; float (*vertexCos)[3] = vertexCos_Store ? vertexCos_Store : vertexCos_Real; Scene *scene = mcmd->modifier.scene; @@ -197,8 +197,8 @@ static void meshcache_do( /* the moons align! */ int i; - float (*vertexCos_Source)[3] = MEM_mallocN(sizeof(*vertexCos_Source) * numVerts, __func__); - float (*vertexCos_New)[3] = MEM_mallocN(sizeof(*vertexCos_New) * numVerts, __func__); + float (*vertexCos_Source)[3] = MEM_malloc_arrayN(numVerts, sizeof(*vertexCos_Source), __func__); + float (*vertexCos_New)[3] = MEM_malloc_arrayN(numVerts, sizeof(*vertexCos_New), __func__); MVert *mv = me->mvert; for (i = 0; i < numVerts; i++, mv++) { diff --git a/source/blender/modifiers/intern/MOD_meshdeform.c b/source/blender/modifiers/intern/MOD_meshdeform.c index 47b51ac170b..da233a18d0a 100644 --- a/source/blender/modifiers/intern/MOD_meshdeform.c +++ b/source/blender/modifiers/intern/MOD_meshdeform.c @@ -361,7 +361,7 @@ static void meshdeformModifier_do( return; } - cagecos = MEM_mallocN(sizeof(*cagecos) * totcagevert, "meshdeformModifier vertCos"); + cagecos = MEM_malloc_arrayN(totcagevert, sizeof(*cagecos), "meshdeformModifier vertCos"); /* setup deformation data */ cagedm->getVertCos(cagedm, cagecos); @@ -370,7 +370,7 @@ static void meshdeformModifier_do( /* We allocate 1 element extra to make it possible to * load the values to SSE registers, which are float4. */ - dco = MEM_callocN(sizeof(*dco) * (totcagevert + 1), "MDefDco"); + dco = MEM_calloc_arrayN((totcagevert + 1), sizeof(*dco), "MDefDco"); zero_v3(dco[totcagevert]); for (a = 0; a < totcagevert; a++) { /* get cage vertex in world space with binding transform */ @@ -467,8 +467,8 @@ void modifier_mdef_compact_influences(ModifierData *md) } /* allocate bind influences */ - mmd->bindinfluences = MEM_callocN(sizeof(MDefInfluence) * mmd->totinfluence, "MDefBindInfluence"); - mmd->bindoffsets = MEM_callocN(sizeof(int) * (totvert + 1), "MDefBindOffset"); + mmd->bindinfluences = MEM_calloc_arrayN(mmd->totinfluence, sizeof(MDefInfluence), "MDefBindInfluence"); + mmd->bindoffsets = MEM_calloc_arrayN((totvert + 1), sizeof(int), "MDefBindOffset"); /* write influences */ totinfluence = 0; diff --git a/source/blender/modifiers/intern/MOD_mirror.c b/source/blender/modifiers/intern/MOD_mirror.c index db06dc43b8e..1b725e335a4 100644 --- a/source/blender/modifiers/intern/MOD_mirror.c +++ b/source/blender/modifiers/intern/MOD_mirror.c @@ -167,7 +167,7 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd, if (do_vtargetmap) { /* second half is filled with -1 */ - vtargetmap = MEM_mallocN(sizeof(int) * maxVerts * 2, "MOD_mirror tarmap"); + vtargetmap = MEM_malloc_arrayN(maxVerts, 2 * sizeof(int), "MOD_mirror tarmap"); vtmap_a = vtargetmap; vtmap_b = vtargetmap + maxVerts; diff --git a/source/blender/modifiers/intern/MOD_normal_edit.c b/source/blender/modifiers/intern/MOD_normal_edit.c index 1c7c640b971..61a5b9bb03e 100644 --- a/source/blender/modifiers/intern/MOD_normal_edit.c +++ b/source/blender/modifiers/intern/MOD_normal_edit.c @@ -117,7 +117,7 @@ static void mix_normals( int i; if (dvert) { - facs = MEM_mallocN(sizeof(*facs) * (size_t)num_loops, __func__); + facs = MEM_malloc_arrayN((size_t)num_loops, sizeof(*facs), __func__); BKE_defvert_extract_vgroup_to_loopweights( dvert, defgrp_index, num_verts, mloop, num_loops, facs, use_invert_vgroup); } @@ -195,8 +195,8 @@ static void normalEditModifier_do_radial( { int i; - float (*cos)[3] = MEM_mallocN(sizeof(*cos) * num_verts, __func__); - float (*nos)[3] = MEM_mallocN(sizeof(*nos) * num_loops, __func__); + float (*cos)[3] = MEM_malloc_arrayN((size_t)num_verts, sizeof(*cos), __func__); + float (*nos)[3] = MEM_malloc_arrayN((size_t)num_loops, sizeof(*nos), __func__); float size[3]; BLI_bitmap *done_verts = BLI_BITMAP_NEW((size_t)num_verts, __func__); @@ -294,8 +294,8 @@ static void normalEditModifier_do_directional( { const bool use_parallel_normals = (enmd->flag & MOD_NORMALEDIT_USE_DIRECTION_PARALLEL) != 0; - float (*cos)[3] = MEM_mallocN(sizeof(*cos) * num_verts, __func__); - float (*nos)[3] = MEM_mallocN(sizeof(*nos) * num_loops, __func__); + float (*cos)[3] = MEM_malloc_arrayN((size_t)num_verts, sizeof(*cos), __func__); + float (*nos)[3] = MEM_malloc_arrayN((size_t)num_loops, sizeof(*nos), __func__); float target_co[3]; int i; @@ -434,7 +434,7 @@ static DerivedMesh *normalEditModifier_do(NormalEditModifierData *enmd, Object * polynors = dm->getPolyDataArray(dm, CD_NORMAL); if (!polynors) { - polynors = MEM_mallocN(sizeof(*polynors) * num_polys, __func__); + polynors = MEM_malloc_arrayN((size_t)num_polys, sizeof(*polynors), __func__); BKE_mesh_calc_normals_poly(mvert, NULL, num_verts, mloop, mpoly, num_loops, num_polys, polynors, false); free_polynors = true; } diff --git a/source/blender/modifiers/intern/MOD_particleinstance.c b/source/blender/modifiers/intern/MOD_particleinstance.c index de59635f335..09966da13a2 100644 --- a/source/blender/modifiers/intern/MOD_particleinstance.c +++ b/source/blender/modifiers/intern/MOD_particleinstance.c @@ -220,7 +220,7 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte if (pimd->flag & eParticleInstanceFlag_UseSize) { float *si; - si = size = MEM_callocN(totpart * sizeof(float), "particle size array"); + si = size = MEM_calloc_arrayN(totpart, sizeof(float), "particle size array"); 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.c b/source/blender/modifiers/intern/MOD_screw.c index 010bf8bf092..979dc339e4e 100644 --- a/source/blender/modifiers/intern/MOD_screw.c +++ b/source/blender/modifiers/intern/MOD_screw.c @@ -139,7 +139,7 @@ static DerivedMesh *dm_remove_doubles_on_axis( if (tot_doubles != 0) { uint tot = totvert * step_tot; - int *full_doubles_map = MEM_mallocN(sizeof(int) * tot, __func__); + int *full_doubles_map = MEM_malloc_arrayN(tot, sizeof(int), __func__); copy_vn_i(full_doubles_map, (int)tot, -1); uint tot_doubles_left = tot_doubles; @@ -448,10 +448,10 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte mpoly_orig = dm->getPolyArray(dm); mloop_orig = dm->getLoopArray(dm); - edge_poly_map = MEM_mallocN(sizeof(*edge_poly_map) * totedge, __func__); + edge_poly_map = MEM_malloc_arrayN(totedge, sizeof(*edge_poly_map), __func__); memset(edge_poly_map, 0xff, sizeof(*edge_poly_map) * totedge); - vert_loop_map = MEM_mallocN(sizeof(*vert_loop_map) * totvert, __func__); + vert_loop_map = MEM_malloc_arrayN(totvert, sizeof(*vert_loop_map), __func__); memset(vert_loop_map, 0xff, sizeof(*vert_loop_map) * totvert); for (i = 0, mp_orig = mpoly_orig; i < totpoly; i++, mp_orig++) { @@ -497,7 +497,7 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte * This makes the modifier faster with one less alloc. */ - vert_connect = MEM_mallocN(sizeof(ScrewVertConnect) * totvert, "ScrewVertConnect"); + vert_connect = MEM_malloc_arrayN(totvert, sizeof(ScrewVertConnect), "ScrewVertConnect"); //vert_connect = (ScrewVertConnect *) &medge_new[totvert]; /* skip the first slice of verts */ vc = vert_connect; diff --git a/source/blender/modifiers/intern/MOD_skin.c b/source/blender/modifiers/intern/MOD_skin.c index 9d1c6913c1c..97afe6d5e87 100644 --- a/source/blender/modifiers/intern/MOD_skin.c +++ b/source/blender/modifiers/intern/MOD_skin.c @@ -419,7 +419,7 @@ static Frame **collect_hull_frames(int v, SkinNode *frames, int nbr, i; (*tothullframe) = emap[v].count; - hull_frames = MEM_callocN(sizeof(Frame *) * (*tothullframe), + hull_frames = MEM_calloc_arrayN((*tothullframe), sizeof(Frame *), "hull_from_frames.hull_frames"); i = 0; for (nbr = 0; nbr < emap[v].count; nbr++) { @@ -600,7 +600,7 @@ static SkinNode *build_frames(const MVert *mvert, int totvert, SkinNode *skin_nodes; int v; - skin_nodes = MEM_callocN(sizeof(SkinNode) * totvert, "build_frames.skin_nodes"); + skin_nodes = MEM_calloc_arrayN(totvert, sizeof(SkinNode), "build_frames.skin_nodes"); for (v = 0; v < totvert; v++) { if (emap[v].count <= 1) @@ -722,7 +722,7 @@ static EMat *build_edge_mats(const MVertSkin *vs, stack = BLI_stack_new(sizeof(stack_elem), "build_edge_mats.stack"); visited_e = BLI_BITMAP_NEW(totedge, "build_edge_mats.visited_e"); - emat = MEM_callocN(sizeof(EMat) * totedge, "build_edge_mats.emat"); + emat = MEM_calloc_arrayN(totedge, sizeof(EMat), "build_edge_mats.emat"); /* Edge matrices are built from the root nodes, add all roots with * children to the stack */ @@ -836,14 +836,14 @@ static DerivedMesh *subdivide_base(DerivedMesh *orig) totorigedge = orig->getNumEdges(orig); /* Get degree of all vertices */ - degree = MEM_callocN(sizeof(int) * totorigvert, "degree"); + degree = MEM_calloc_arrayN(totorigvert, sizeof(int), "degree"); for (i = 0; i < totorigedge; i++) { degree[origedge[i].v1]++; degree[origedge[i].v2]++; } /* Per edge, store how many subdivisions are needed */ - edge_subd = MEM_callocN(sizeof(int) * totorigedge, "edge_subd"); + edge_subd = MEM_calloc_arrayN(totorigedge, sizeof(int), "edge_subd"); for (i = 0, totsubd = 0; i < totorigedge; i++) { edge_subd[i] += calc_edge_subdivisions(origvert, orignode, &origedge[i], degree); @@ -882,7 +882,7 @@ static DerivedMesh *subdivide_base(DerivedMesh *orig) if (origdvert) { const MDeformVert *dv1 = &origdvert[e->v1]; const MDeformVert *dv2 = &origdvert[e->v2]; - vgroups = MEM_callocN(sizeof(*vgroups) * dv1->totweight, "vgroup"); + vgroups = MEM_calloc_arrayN(dv1->totweight, sizeof(*vgroups), "vgroup"); /* Only want vertex groups used by both vertices */ for (j = 0; j < dv1->totweight; j++) { diff --git a/source/blender/modifiers/intern/MOD_smooth.c b/source/blender/modifiers/intern/MOD_smooth.c index be55030e18a..91c724cd1c9 100644 --- a/source/blender/modifiers/intern/MOD_smooth.c +++ b/source/blender/modifiers/intern/MOD_smooth.c @@ -102,10 +102,10 @@ static void smoothModifier_do( unsigned char *uctmp; float *ftmp, fac, facm; - ftmp = (float *)MEM_callocN(3 * sizeof(float) * numVerts, + ftmp = (float *)MEM_calloc_arrayN(numVerts, 3 * sizeof(float), "smoothmodifier_f"); if (!ftmp) return; - uctmp = (unsigned char *)MEM_callocN(sizeof(unsigned char) * numVerts, + uctmp = (unsigned char *)MEM_calloc_arrayN(numVerts, sizeof(unsigned char), "smoothmodifier_uc"); if (!uctmp) { if (ftmp) MEM_freeN(ftmp); diff --git a/source/blender/modifiers/intern/MOD_solidify.c b/source/blender/modifiers/intern/MOD_solidify.c index 14b29855728..5635d37f100 100644 --- a/source/blender/modifiers/intern/MOD_solidify.c +++ b/source/blender/modifiers/intern/MOD_solidify.c @@ -101,7 +101,7 @@ static void dm_calc_normal(DerivedMesh *dm, float (*face_nors)[3], float (*r_ver mp = mpoly; { - EdgeFaceRef *edge_ref_array = MEM_callocN(sizeof(EdgeFaceRef) * (size_t)numEdges, "Edge Connectivity"); + EdgeFaceRef *edge_ref_array = MEM_calloc_arrayN((size_t)numEdges, sizeof(EdgeFaceRef), "Edge Connectivity"); EdgeFaceRef *edge_ref; float edge_normal[3]; @@ -235,7 +235,7 @@ static DerivedMesh *applyModifier( unsigned int *new_edge_arr = NULL; STACK_DECLARE(new_edge_arr); - unsigned int *old_vert_arr = MEM_callocN(sizeof(*old_vert_arr) * (size_t)numVerts, "old_vert_arr in solidify"); + unsigned int *old_vert_arr = MEM_calloc_arrayN(numVerts, sizeof(*old_vert_arr), "old_vert_arr in solidify"); unsigned int *edge_users = NULL; char *edge_order = NULL; @@ -270,7 +270,7 @@ static DerivedMesh *applyModifier( if (need_face_normals) { /* calculate only face normals */ - face_nors = MEM_mallocN(sizeof(*face_nors) * (size_t)numFaces, __func__); + face_nors = MEM_malloc_arrayN(numFaces, sizeof(*face_nors), __func__); BKE_mesh_calc_normals_poly( orig_mvert, NULL, (int)numVerts, orig_mloop, orig_mpoly, @@ -289,11 +289,11 @@ static DerivedMesh *applyModifier( #define INVALID_UNUSED ((unsigned int)-1) #define INVALID_PAIR ((unsigned int)-2) - new_vert_arr = MEM_mallocN(sizeof(*new_vert_arr) * (size_t)(numVerts * 2), __func__); - new_edge_arr = MEM_mallocN(sizeof(*new_edge_arr) * (size_t)((numEdges * 2) + numVerts), __func__); + new_vert_arr = MEM_malloc_arrayN(numVerts, 2 * sizeof(*new_vert_arr), __func__); + new_edge_arr = MEM_malloc_arrayN(((numEdges * 2) + numVerts), sizeof(*new_edge_arr), __func__); - edge_users = MEM_mallocN(sizeof(*edge_users) * (size_t)numEdges, "solid_mod edges"); - edge_order = MEM_mallocN(sizeof(*edge_order) * (size_t)numEdges, "solid_mod eorder"); + edge_users = MEM_malloc_arrayN(numEdges, sizeof(*edge_users), "solid_mod edges"); + edge_order = MEM_malloc_arrayN(numEdges, sizeof(*edge_order), "solid_mod eorder"); /* save doing 2 loops here... */ @@ -366,7 +366,7 @@ static DerivedMesh *applyModifier( } if (smd->flag & MOD_SOLIDIFY_NORMAL_CALC) { - vert_nors = MEM_callocN(sizeof(float) * (size_t)numVerts * 3, "mod_solid_vno_hq"); + vert_nors = MEM_calloc_arrayN(numVerts, 3 * sizeof(float), "mod_solid_vno_hq"); dm_calc_normal(dm, face_nors, vert_nors); } @@ -517,7 +517,7 @@ static DerivedMesh *applyModifier( if (do_clamp) { unsigned int i; - vert_lens = MEM_mallocN(sizeof(float) * numVerts, "vert_lens"); + vert_lens = MEM_malloc_arrayN(numVerts, sizeof(float), "vert_lens"); copy_vn_fl(vert_lens, (int)numVerts, FLT_MAX); for (i = 0; i < numEdges; i++) { const float ed_len_sq = len_squared_v3v3(mvert[medge[i].v1].co, mvert[medge[i].v2].co); @@ -596,13 +596,13 @@ static DerivedMesh *applyModifier( const bool check_non_manifold = (smd->flag & MOD_SOLIDIFY_NORMAL_CALC) != 0; #endif /* same as EM_solidify() in editmesh_lib.c */ - float *vert_angles = MEM_callocN(sizeof(float) * numVerts * 2, "mod_solid_pair"); /* 2 in 1 */ + float *vert_angles = MEM_calloc_arrayN(numVerts, 2 * sizeof(float), "mod_solid_pair"); /* 2 in 1 */ float *vert_accum = vert_angles + numVerts; unsigned int vidx; unsigned int i; if (vert_nors == NULL) { - vert_nors = MEM_mallocN(sizeof(float) * numVerts * 3, "mod_solid_vno"); + vert_nors = MEM_malloc_arrayN(numVerts, 3 * sizeof(float), "mod_solid_vno"); for (i = 0, mv = mvert; i < numVerts; i++, mv++) { normal_short_to_float_v3(vert_nors[i], mv->no); } @@ -682,7 +682,7 @@ static DerivedMesh *applyModifier( } if (do_clamp) { - float *vert_lens_sq = MEM_mallocN(sizeof(float) * numVerts, "vert_lens"); + float *vert_lens_sq = MEM_malloc_arrayN(numVerts, sizeof(float), "vert_lens"); const float offset = fabsf(smd->offset) * smd->offset_clamp; const float offset_sq = offset * offset; copy_vn_fl(vert_lens_sq, (int)numVerts, FLT_MAX); @@ -765,7 +765,7 @@ static DerivedMesh *applyModifier( #ifdef SOLIDIFY_SIDE_NORMALS const bool do_side_normals = !(result->dirty & DM_DIRTY_NORMALS); /* annoying to allocate these since we only need the edge verts, */ - float (*edge_vert_nos)[3] = do_side_normals ? MEM_callocN(sizeof(float) * numVerts * 3, __func__) : NULL; + float (*edge_vert_nos)[3] = do_side_normals ? MEM_calloc_arrayN(numVerts, 3 * sizeof(float), __func__) : NULL; float nor[3]; #endif const unsigned char crease_rim = smd->crease_rim * 255.0f; diff --git a/source/blender/modifiers/intern/MOD_surface.c b/source/blender/modifiers/intern/MOD_surface.c index c408b4fbd63..bef35ccf1fe 100644 --- a/source/blender/modifiers/intern/MOD_surface.c +++ b/source/blender/modifiers/intern/MOD_surface.c @@ -130,8 +130,8 @@ static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED surmd->v = NULL; } - surmd->x = MEM_callocN(numverts * sizeof(MVert), "MVert"); - surmd->v = MEM_callocN(numverts * sizeof(MVert), "MVert"); + surmd->x = MEM_calloc_arrayN(numverts, sizeof(MVert), "MVert"); + surmd->v = MEM_calloc_arrayN(numverts, sizeof(MVert), "MVert"); surmd->numverts = numverts; diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.c b/source/blender/modifiers/intern/MOD_surfacedeform.c index cef64e91669..046a0ab27bf 100644 --- a/source/blender/modifiers/intern/MOD_surfacedeform.c +++ b/source/blender/modifiers/intern/MOD_surfacedeform.c @@ -388,7 +388,7 @@ BLI_INLINE SDefBindWeightData *computeBindWeights(SDefBindCalcData * const data, bwdata->numpoly = data->vert_edges[nearest].num / 2; - bpoly = MEM_callocN(sizeof(*bpoly) * bwdata->numpoly, "SDefBindPoly"); + bpoly = MEM_calloc_arrayN(bwdata->numpoly, sizeof(*bpoly), "SDefBindPoly"); if (bpoly == NULL) { freeBindData(bwdata); data->success = MOD_SDEF_BIND_RESULT_MEM_ERR; @@ -431,14 +431,14 @@ BLI_INLINE SDefBindWeightData *computeBindWeights(SDefBindCalcData * const data, bpoly->numverts = poly->totloop; bpoly->loopstart = poly->loopstart; - bpoly->coords = MEM_mallocN(sizeof(*bpoly->coords) * poly->totloop, "SDefBindPolyCoords"); + bpoly->coords = MEM_malloc_arrayN(poly->totloop, sizeof(*bpoly->coords), "SDefBindPolyCoords"); if (bpoly->coords == NULL) { freeBindData(bwdata); data->success = MOD_SDEF_BIND_RESULT_MEM_ERR; return NULL; } - bpoly->coords_v2 = MEM_mallocN(sizeof(*bpoly->coords_v2) * poly->totloop, "SDefBindPolyCoords_v2"); + bpoly->coords_v2 = MEM_malloc_arrayN(poly->totloop, sizeof(*bpoly->coords_v2), "SDefBindPolyCoords_v2"); if (bpoly->coords_v2 == NULL) { freeBindData(bwdata); data->success = MOD_SDEF_BIND_RESULT_MEM_ERR; @@ -765,7 +765,7 @@ static void bindVert( return; } - sdvert->binds = MEM_callocN(sizeof(*sdvert->binds) * bwdata->numbinds, "SDefVertBindData"); + sdvert->binds = MEM_calloc_arrayN(bwdata->numbinds, sizeof(*sdvert->binds), "SDefVertBindData"); if (sdvert->binds == NULL) { data->success = MOD_SDEF_BIND_RESULT_MEM_ERR; sdvert->numbinds = 0; @@ -787,13 +787,13 @@ static void bindVert( sdbind->numverts = bpoly->numverts; sdbind->mode = MOD_SDEF_MODE_NGON; - sdbind->vert_weights = MEM_mallocN(sizeof(*sdbind->vert_weights) * bpoly->numverts, "SDefNgonVertWeights"); + sdbind->vert_weights = MEM_malloc_arrayN(bpoly->numverts, sizeof(*sdbind->vert_weights), "SDefNgonVertWeights"); if (sdbind->vert_weights == NULL) { data->success = MOD_SDEF_BIND_RESULT_MEM_ERR; return; } - sdbind->vert_inds = MEM_mallocN(sizeof(*sdbind->vert_inds) * bpoly->numverts, "SDefNgonVertInds"); + sdbind->vert_inds = MEM_malloc_arrayN(bpoly->numverts, sizeof(*sdbind->vert_inds), "SDefNgonVertInds"); if (sdbind->vert_inds == NULL) { data->success = MOD_SDEF_BIND_RESULT_MEM_ERR; return; @@ -823,13 +823,13 @@ static void bindVert( sdbind->numverts = bpoly->numverts; sdbind->mode = MOD_SDEF_MODE_CENTROID; - sdbind->vert_weights = MEM_mallocN(sizeof(*sdbind->vert_weights) * 3, "SDefCentVertWeights"); + sdbind->vert_weights = MEM_malloc_arrayN(3, sizeof(*sdbind->vert_weights), "SDefCentVertWeights"); if (sdbind->vert_weights == NULL) { data->success = MOD_SDEF_BIND_RESULT_MEM_ERR; return; } - sdbind->vert_inds = MEM_mallocN(sizeof(*sdbind->vert_inds) * bpoly->numverts, "SDefCentVertInds"); + sdbind->vert_inds = MEM_malloc_arrayN(bpoly->numverts, sizeof(*sdbind->vert_inds), "SDefCentVertInds"); if (sdbind->vert_inds == NULL) { data->success = MOD_SDEF_BIND_RESULT_MEM_ERR; return; @@ -866,13 +866,13 @@ static void bindVert( sdbind->numverts = bpoly->numverts; sdbind->mode = MOD_SDEF_MODE_LOOPTRI; - sdbind->vert_weights = MEM_mallocN(sizeof(*sdbind->vert_weights) * 3, "SDefTriVertWeights"); + sdbind->vert_weights = MEM_malloc_arrayN(3, sizeof(*sdbind->vert_weights), "SDefTriVertWeights"); if (sdbind->vert_weights == NULL) { data->success = MOD_SDEF_BIND_RESULT_MEM_ERR; return; } - sdbind->vert_inds = MEM_mallocN(sizeof(*sdbind->vert_inds) * bpoly->numverts, "SDefTriVertInds"); + sdbind->vert_inds = MEM_malloc_arrayN(bpoly->numverts, sizeof(*sdbind->vert_inds), "SDefTriVertInds"); if (sdbind->vert_inds == NULL) { data->success = MOD_SDEF_BIND_RESULT_MEM_ERR; return; @@ -923,20 +923,20 @@ static bool surfacedeformBind(SurfaceDeformModifierData *smd, float (*vertexCos) SDefAdjacency *adj_array; SDefEdgePolys *edge_polys; - vert_edges = MEM_callocN(sizeof(*vert_edges) * tnumverts, "SDefVertEdgeMap"); + vert_edges = MEM_calloc_arrayN(tnumverts, sizeof(*vert_edges), "SDefVertEdgeMap"); if (vert_edges == NULL) { modifier_setError((ModifierData *)smd, "Out of memory"); return false; } - adj_array = MEM_mallocN(sizeof(*adj_array) * tnumedges * 2, "SDefVertEdge"); + adj_array = MEM_malloc_arrayN(tnumedges, 2 * sizeof(*adj_array), "SDefVertEdge"); if (adj_array == NULL) { modifier_setError((ModifierData *)smd, "Out of memory"); MEM_freeN(vert_edges); return false; } - edge_polys = MEM_callocN(sizeof(*edge_polys) * tnumedges, "SDefEdgeFaceMap"); + edge_polys = MEM_calloc_arrayN(tnumedges, sizeof(*edge_polys), "SDefEdgeFaceMap"); if (edge_polys == NULL) { modifier_setError((ModifierData *)smd, "Out of memory"); MEM_freeN(vert_edges); @@ -944,7 +944,7 @@ static bool surfacedeformBind(SurfaceDeformModifierData *smd, float (*vertexCos) return false; } - smd->verts = MEM_mallocN(sizeof(*smd->verts) * numverts, "SDefBindVerts"); + smd->verts = MEM_malloc_arrayN(numverts, sizeof(*smd->verts), "SDefBindVerts"); if (smd->verts == NULL) { modifier_setError((ModifierData *)smd, "Out of memory"); freeAdjacencyMap(vert_edges, adj_array, edge_polys); @@ -981,7 +981,7 @@ static bool surfacedeformBind(SurfaceDeformModifierData *smd, float (*vertexCos) .medge = medge, .mloop = mloop, .looptri = tdm->getLoopTriArray(tdm), - .targetCos = MEM_mallocN(sizeof(float[3]) * tnumverts, "SDefTargetBindVertArray"), + .targetCos = MEM_malloc_arrayN(tnumverts, sizeof(float[3]), "SDefTargetBindVertArray"), .bind_verts = smd->verts, .vertexCos = vertexCos, .falloff = smd->falloff, @@ -1054,7 +1054,7 @@ static void deformVert( for (int j = 0; j < data->bind_verts[index].numbinds; j++, sdbind++) { /* Mode-generic operations (allocate poly coordinates) */ - float (*coords)[3] = MEM_mallocN(sizeof(*coords) * sdbind->numverts, "SDefDoPolyCoords"); + float (*coords)[3] = MEM_malloc_arrayN(sdbind->numverts, sizeof(*coords), "SDefDoPolyCoords"); for (int k = 0; k < sdbind->numverts; k++) { copy_v3_v3(coords[k], data->targetCos[sdbind->vert_inds[k]]); @@ -1152,7 +1152,7 @@ static void surfacedeformModifier_do(ModifierData *md, float (*vertexCos)[3], un /* Actual vertex location update starts here */ SDefDeformData data = { .bind_verts = smd->verts, - .targetCos = MEM_mallocN(sizeof(float[3]) * tnumverts, "SDefTargetVertArray"), + .targetCos = MEM_malloc_arrayN(tnumverts, sizeof(float[3]), "SDefTargetVertArray"), .vertexCos = vertexCos, }; diff --git a/source/blender/modifiers/intern/MOD_util.c b/source/blender/modifiers/intern/MOD_util.c index ded1f0b77e6..5b19bcf4817 100644 --- a/source/blender/modifiers/intern/MOD_util.c +++ b/source/blender/modifiers/intern/MOD_util.c @@ -87,7 +87,7 @@ void get_texture_coords(MappingInfoModifierData *dmd, Object *ob, MPoly *mpoly = dm->getPolyArray(dm); MPoly *mp; MLoop *mloop = dm->getLoopArray(dm); - char *done = MEM_callocN(sizeof(*done) * numVerts, + char *done = MEM_calloc_arrayN(numVerts, sizeof(*done), "get_texture_coords done"); int numPolys = dm->getNumPolys(dm); char uvname[MAX_CUSTOMDATA_LAYER_NAME]; diff --git a/source/blender/modifiers/intern/MOD_uvproject.c b/source/blender/modifiers/intern/MOD_uvproject.c index c9a842621b6..498dd2486f4 100644 --- a/source/blender/modifiers/intern/MOD_uvproject.c +++ b/source/blender/modifiers/intern/MOD_uvproject.c @@ -226,7 +226,7 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, numVerts = dm->getNumVerts(dm); - coords = MEM_mallocN(sizeof(*coords) * numVerts, + coords = MEM_malloc_arrayN(numVerts, sizeof(*coords), "uvprojectModifier_do coords"); dm->getVertCos(dm, coords); diff --git a/source/blender/modifiers/intern/MOD_warp.c b/source/blender/modifiers/intern/MOD_warp.c index 566ee5b2d24..be0be2671b9 100644 --- a/source/blender/modifiers/intern/MOD_warp.c +++ b/source/blender/modifiers/intern/MOD_warp.c @@ -214,7 +214,7 @@ static void warpModifier_do(WarpModifierData *wmd, Object *ob, weight = strength; if (wmd->texture) { - tex_co = MEM_mallocN(sizeof(*tex_co) * numVerts, "warpModifier_do tex_co"); + tex_co = MEM_malloc_arrayN(numVerts, sizeof(*tex_co), "warpModifier_do tex_co"); get_texture_coords((MappingInfoModifierData *)wmd, ob, dm, vertexCos, tex_co, numVerts); modifier_init_texture(wmd->modifier.scene, wmd->texture); diff --git a/source/blender/modifiers/intern/MOD_wave.c b/source/blender/modifiers/intern/MOD_wave.c index c408f244afd..1271cccd719 100644 --- a/source/blender/modifiers/intern/MOD_wave.c +++ b/source/blender/modifiers/intern/MOD_wave.c @@ -206,7 +206,7 @@ static void waveModifier_do(WaveModifierData *md, } if (wmd->texture) { - tex_co = MEM_mallocN(sizeof(*tex_co) * numVerts, + tex_co = MEM_malloc_arrayN(numVerts, sizeof(*tex_co), "waveModifier_do tex_co"); get_texture_coords((MappingInfoModifierData *)wmd, ob, dm, vertexCos, tex_co, numVerts); diff --git a/source/blender/modifiers/intern/MOD_weightvg_util.c b/source/blender/modifiers/intern/MOD_weightvg_util.c index da7230ed5af..416f2964d6e 100644 --- a/source/blender/modifiers/intern/MOD_weightvg_util.c +++ b/source/blender/modifiers/intern/MOD_weightvg_util.c @@ -143,9 +143,9 @@ void weightvg_do_mask(int num, const int *indices, float *org_w, const float *ne t_map.map_object = tex_map_object; BLI_strncpy(t_map.uvlayer_name, tex_uvlayer_name, sizeof(t_map.uvlayer_name)); t_map.texmapping = tex_mapping; - v_co = MEM_mallocN(sizeof(*v_co) * numVerts, "WeightVG Modifier, TEX mode, v_co"); + v_co = MEM_malloc_arrayN(numVerts, sizeof(*v_co), "WeightVG Modifier, TEX mode, v_co"); dm->getVertCos(dm, v_co); - tex_co = MEM_callocN(sizeof(*tex_co) * numVerts, "WeightVG Modifier, TEX mode, tex_co"); + tex_co = MEM_calloc_arrayN(numVerts, sizeof(*tex_co), "WeightVG Modifier, TEX mode, tex_co"); get_texture_coords(&t_map, ob, dm, v_co, tex_co, num); MEM_freeN(v_co); diff --git a/source/blender/modifiers/intern/MOD_weightvgedit.c b/source/blender/modifiers/intern/MOD_weightvgedit.c index dbdaafaa5a7..9aa4bad1707 100644 --- a/source/blender/modifiers/intern/MOD_weightvgedit.c +++ b/source/blender/modifiers/intern/MOD_weightvgedit.c @@ -213,9 +213,9 @@ static DerivedMesh *applyModifier(ModifierData *md, } /* Get org weights, assuming 0.0 for vertices not in given vgroup. */ - org_w = MEM_mallocN(sizeof(float) * numVerts, "WeightVGEdit Modifier, org_w"); - new_w = MEM_mallocN(sizeof(float) * numVerts, "WeightVGEdit Modifier, new_w"); - dw = MEM_mallocN(sizeof(MDeformWeight *) * numVerts, "WeightVGEdit Modifier, dw"); + org_w = MEM_malloc_arrayN(numVerts, sizeof(float), "WeightVGEdit Modifier, org_w"); + new_w = MEM_malloc_arrayN(numVerts, sizeof(float), "WeightVGEdit Modifier, new_w"); + dw = MEM_malloc_arrayN(numVerts, sizeof(MDeformWeight *), "WeightVGEdit Modifier, dw"); for (i = 0; i < numVerts; i++) { dw[i] = defvert_find_index(&dvert[i], defgrp_index); if (dw[i]) { diff --git a/source/blender/modifiers/intern/MOD_weightvgmix.c b/source/blender/modifiers/intern/MOD_weightvgmix.c index 5f30d4ca72a..ab1264cc9a0 100644 --- a/source/blender/modifiers/intern/MOD_weightvgmix.c +++ b/source/blender/modifiers/intern/MOD_weightvgmix.c @@ -265,9 +265,9 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte return dm; } /* Find out which vertices to work on. */ - tidx = MEM_mallocN(sizeof(int) * numVerts, "WeightVGMix Modifier, tidx"); - tdw1 = MEM_mallocN(sizeof(MDeformWeight *) * numVerts, "WeightVGMix Modifier, tdw1"); - tdw2 = MEM_mallocN(sizeof(MDeformWeight *) * numVerts, "WeightVGMix Modifier, tdw2"); + tidx = MEM_malloc_arrayN(numVerts, sizeof(int), "WeightVGMix Modifier, tidx"); + tdw1 = MEM_malloc_arrayN(numVerts, sizeof(MDeformWeight *), "WeightVGMix Modifier, tdw1"); + tdw2 = MEM_malloc_arrayN(numVerts, sizeof(MDeformWeight *), "WeightVGMix Modifier, tdw2"); switch (wmd->mix_set) { case MOD_WVG_SET_A: /* All vertices in first vgroup. */ @@ -333,12 +333,12 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte return dm; } if (numIdx != -1) { - indices = MEM_mallocN(sizeof(int) * numIdx, "WeightVGMix Modifier, indices"); + indices = MEM_malloc_arrayN(numIdx, sizeof(int), "WeightVGMix Modifier, indices"); memcpy(indices, tidx, sizeof(int) * numIdx); - dw1 = MEM_mallocN(sizeof(MDeformWeight *) * numIdx, "WeightVGMix Modifier, dw1"); + dw1 = MEM_malloc_arrayN(numIdx, sizeof(MDeformWeight *), "WeightVGMix Modifier, dw1"); memcpy(dw1, tdw1, sizeof(MDeformWeight *) * numIdx); MEM_freeN(tdw1); - dw2 = MEM_mallocN(sizeof(MDeformWeight *) * numIdx, "WeightVGMix Modifier, dw2"); + dw2 = MEM_malloc_arrayN(numIdx, sizeof(MDeformWeight *), "WeightVGMix Modifier, dw2"); memcpy(dw2, tdw2, sizeof(MDeformWeight *) * numIdx); MEM_freeN(tdw2); } @@ -351,8 +351,8 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte } MEM_freeN(tidx); - org_w = MEM_mallocN(sizeof(float) * numIdx, "WeightVGMix Modifier, org_w"); - new_w = MEM_mallocN(sizeof(float) * numIdx, "WeightVGMix Modifier, new_w"); + org_w = MEM_malloc_arrayN(numIdx, sizeof(float), "WeightVGMix Modifier, org_w"); + new_w = MEM_malloc_arrayN(numIdx, sizeof(float), "WeightVGMix Modifier, new_w"); /* Mix weights. */ for (i = 0; i < numIdx; i++) { diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c index 787e712853a..8a5d0f833a8 100644 --- a/source/blender/modifiers/intern/MOD_weightvgproximity.c +++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c @@ -433,9 +433,9 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte /* Find out which vertices to work on (all vertices in vgroup), and get their relevant weight. */ - tidx = MEM_mallocN(sizeof(int) * numVerts, "WeightVGProximity Modifier, tidx"); - tw = MEM_mallocN(sizeof(float) * numVerts, "WeightVGProximity Modifier, tw"); - tdw = MEM_mallocN(sizeof(MDeformWeight *) * numVerts, "WeightVGProximity Modifier, tdw"); + tidx = MEM_malloc_arrayN(numVerts, sizeof(int), "WeightVGProximity Modifier, tidx"); + tw = MEM_malloc_arrayN(numVerts, sizeof(float), "WeightVGProximity Modifier, tw"); + tdw = MEM_malloc_arrayN(numVerts, sizeof(MDeformWeight *), "WeightVGProximity Modifier, tdw"); for (i = 0; i < numVerts; i++) { MDeformWeight *_dw = defvert_find_index(&dvert[i], defgrp_index); if (_dw) { @@ -452,11 +452,11 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte return dm; } if (numIdx != numVerts) { - indices = MEM_mallocN(sizeof(int) * numIdx, "WeightVGProximity Modifier, indices"); + indices = MEM_malloc_arrayN(numIdx, sizeof(int), "WeightVGProximity Modifier, indices"); memcpy(indices, tidx, sizeof(int) * numIdx); - org_w = MEM_mallocN(sizeof(float) * numIdx, "WeightVGProximity Modifier, org_w"); + org_w = MEM_malloc_arrayN(numIdx, sizeof(float), "WeightVGProximity Modifier, org_w"); memcpy(org_w, tw, sizeof(float) * numIdx); - dw = MEM_mallocN(sizeof(MDeformWeight *) * numIdx, "WeightVGProximity Modifier, dw"); + dw = MEM_malloc_arrayN(numIdx, sizeof(MDeformWeight *), "WeightVGProximity Modifier, dw"); memcpy(dw, tdw, sizeof(MDeformWeight *) * numIdx); MEM_freeN(tw); MEM_freeN(tdw); @@ -465,16 +465,16 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte org_w = tw; dw = tdw; } - new_w = MEM_mallocN(sizeof(float) * numIdx, "WeightVGProximity Modifier, new_w"); + new_w = MEM_malloc_arrayN(numIdx, sizeof(float), "WeightVGProximity Modifier, new_w"); MEM_freeN(tidx); /* Get our vertex coordinates. */ - v_cos = MEM_mallocN(sizeof(float[3]) * numIdx, "WeightVGProximity Modifier, v_cos"); + v_cos = MEM_malloc_arrayN(numIdx, sizeof(float[3]), "WeightVGProximity Modifier, v_cos"); if (numIdx != numVerts) { /* XXX In some situations, this code can be up to about 50 times more performant * than simply using getVertCo for each affected vertex... */ - float (*tv_cos)[3] = MEM_mallocN(sizeof(float[3]) * numVerts, "WeightVGProximity Modifier, tv_cos"); + float (*tv_cos)[3] = MEM_malloc_arrayN(numVerts, sizeof(float[3]), "WeightVGProximity Modifier, tv_cos"); dm->getVertCos(dm, tv_cos); for (i = 0; i < numIdx; i++) copy_v3_v3(v_cos[i], tv_cos[indices[i]]); @@ -513,9 +513,9 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte /* We must check that we do have a valid target_dm! */ if (target_dm) { SpaceTransform loc2trgt; - float *dists_v = use_trgt_verts ? MEM_mallocN(sizeof(float) * numIdx, "dists_v") : NULL; - float *dists_e = use_trgt_edges ? MEM_mallocN(sizeof(float) * numIdx, "dists_e") : NULL; - float *dists_f = use_trgt_faces ? MEM_mallocN(sizeof(float) * numIdx, "dists_f") : NULL; + float *dists_v = use_trgt_verts ? MEM_malloc_arrayN(numIdx, sizeof(float), "dists_v") : NULL; + float *dists_e = use_trgt_edges ? MEM_malloc_arrayN(numIdx, sizeof(float), "dists_e") : NULL; + float *dists_f = use_trgt_faces ? MEM_malloc_arrayN(numIdx, sizeof(float), "dists_f") : NULL; BLI_SPACE_TRANSFORM_SETUP(&loc2trgt, ob, obr); get_vert2geom_distance(numIdx, v_cos, dists_v, dists_e, dists_f, |