Refactor: Use blender::Array for SubdivCCGNeighbors

To avoid requiring callers to remember to free the allocated data.

Pull Request: https://projects.blender.org/blender/blender/pulls/120194
This commit is contained in:
Sean Kim 2024-04-03 02:37:45 +02:00 committed by Hans Goudey
parent d4c7e6f020
commit 06f04a2c19
3 changed files with 4 additions and 21 deletions

View File

@ -220,11 +220,8 @@ void BKE_subdiv_ccg_topology_counters(const SubdivCCG &subdiv_ccg,
int &r_num_loops);
struct SubdivCCGNeighbors {
SubdivCCGCoord *coords;
int size;
blender::Array<SubdivCCGCoord, 256> coords;
int num_duplicates;
SubdivCCGCoord coords_fixed[256];
};
void BKE_subdiv_ccg_print_coord(const char *message, const SubdivCCGCoord &coord);
@ -244,9 +241,6 @@ bool BKE_subdiv_ccg_check_coord_valid(const SubdivCCG &subdiv_ccg, const SubdivC
* element inside of every neighboring grid. */
/* Get actual neighbors of the given coordinate.
*
* SubdivCCGNeighbors.neighbors must be freed if it is not equal to
* SubdivCCGNeighbors.fixed_neighbors.
*
* If include_duplicates is true, vertices in other grids that match
* the current vertex are added at the end of the coords array. */

View File

@ -1004,15 +1004,8 @@ BLI_INLINE void subdiv_ccg_neighbors_init(SubdivCCGNeighbors &neighbors,
const int num_duplicates)
{
const int size = num_unique + num_duplicates;
neighbors.size = size;
neighbors.coords.reinitialize(size);
neighbors.num_duplicates = num_duplicates;
if (size < ARRAY_SIZE(neighbors.coords_fixed)) {
neighbors.coords = neighbors.coords_fixed;
}
else {
neighbors.coords = static_cast<SubdivCCGCoord *>(
MEM_mallocN(sizeof(*neighbors.coords) * size, "SubdivCCGNeighbors.coords"));
}
}
/* Check whether given coordinate belongs to a grid corner. */
@ -1520,7 +1513,7 @@ void BKE_subdiv_ccg_neighbor_coords_get(const SubdivCCG &subdiv_ccg,
}
#ifndef NDEBUG
for (int i = 0; i < r_neighbors.size; i++) {
for (const int i : r_neighbors.coords.index_range()) {
BLI_assert(BKE_subdiv_ccg_check_coord_valid(subdiv_ccg, r_neighbors.coords[i]));
}
#endif

View File

@ -778,7 +778,7 @@ static void sculpt_vertex_neighbors_get_grids(SculptSession *ss,
iter->neighbors = iter->neighbors_fixed;
iter->neighbor_indices = iter->neighbor_indices_fixed;
for (int i = 0; i < neighbors.size; i++) {
for (const int i : neighbors.coords.index_range()) {
int v = neighbors.coords[i].grid_index * key->grid_area +
neighbors.coords[i].y * key->grid_size + neighbors.coords[i].x;
@ -792,10 +792,6 @@ static void sculpt_vertex_neighbors_get_grids(SculptSession *ss,
sculpt_vertex_neighbor_add(iter, BKE_pbvh_make_vref(v), v);
}
}
if (neighbors.coords != neighbors.coords_fixed) {
MEM_freeN(neighbors.coords);
}
}
void SCULPT_vertex_neighbors_get(SculptSession *ss,