Sculpt: Fix T102567: multires crash with high subdivision levels

Previous fix did not work for ngons.
The pbvh leaf limit minimum is now set
to the maximum ngon's vertex count.
This commit is contained in:
Joseph Eagar 2022-11-20 07:30:14 -08:00
parent 567ae90374
commit 7193e5aa10
Notes: blender-bot 2023-02-14 09:17:57 +01:00
Referenced by issue #102567, Regression: sculpt multireslevel 7 crashes Blender
1 changed files with 9 additions and 1 deletions

View File

@ -834,11 +834,19 @@ void BKE_pbvh_build_grids(PBVH *pbvh,
pbvh->grid_hidden = grid_hidden;
pbvh->subdiv_ccg = subdiv_ccg;
/* Find maximum number of grids per face. */
int max_grids = 1;
MPoly *mpoly = BKE_mesh_polys(me);
for (int i = 0; i < me->totpoly; i++) {
max_grids = max_ii(max_grids, mpoly[i].totloop);
}
/* Ensure leaf limit is at least 4 so there's room
* to split at original face boundaries.
* Fixes T102209.
*/
pbvh->leaf_limit = max_ii(LEAF_LIMIT / (gridsize * gridsize), 4);
pbvh->leaf_limit = max_ii(LEAF_LIMIT / (gridsize * gridsize), max_grids);
/* We need the base mesh attribute layout for PBVH draw. */
pbvh->vdata = &me->vdata;