Sculpt-dev: add range checking for vertex ids

This commit is contained in:
Joseph Eagar 2022-01-02 22:15:21 -08:00
parent 8f18ee27e7
commit c5dbd4bc87
3 changed files with 36 additions and 1 deletions

View File

@ -21,6 +21,7 @@
*/
#include "bmesh_class.h"
#include "BLI_compiler_compat.h"
typedef enum {
MULTIRES_SPACE_TANGENT, // convert absolute to tangent
@ -245,4 +246,6 @@ void BM_mesh_vert_coords_apply_with_mat4(BMesh *bm,
BLI_ghash_lookup(bm->idmap.ghash, POINTER_FROM_UINT(id)) : \
bm->idmap.map[id])
#define BM_ELEM_FROM_ID_SAFE(bm, id) (((id) >= 0 && (id) < (bm)->idmap.maxid) ? (BM_ELEM_FROM_ID(bm, id)) : NULL)
bool BM_elem_is_free(BMElem *elem, int htype);

View File

@ -5013,6 +5013,16 @@ static void sculpt_topology_update(Sculpt *sd,
SCULPT_dyntopo_automasking_init(ss, sd, brush, ob, &mask_cb, &mask_cb_data);
int actv = -1, actf = -1;
if (ss->active_vertex_index.i != SCULPT_REF_NONE) {
actv = BM_ELEM_GET_ID(ss->bm, (BMElem *)ss->active_vertex_index.i);
}
if (ss->active_face_index.i != SCULPT_REF_NONE) {
actf = BM_ELEM_GET_ID(ss->bm, (BMElem *)ss->active_face_index.i);
}
/* do nodes under the brush cursor */
modified = BKE_pbvh_bmesh_update_topology_nodes(
ss->pbvh,
@ -5033,6 +5043,28 @@ static void sculpt_topology_update(Sculpt *sd,
SCULPT_dyntopo_automasking_end(mask_cb_data);
if (actv != -1) {
BMVert *v = (BMVert*)BM_ELEM_FROM_ID_SAFE(ss->bm, actv);
if (v && v->head.htype == BM_VERT) {
ss->active_vertex_index.i == (intptr_t)v;
}
else {
ss->active_vertex_index.i = SCULPT_REF_NONE;
}
}
if (actf != -1) {
BMFace *f = (BMFace*)BM_ELEM_FROM_ID_SAFE(ss->bm, actf);
if (f && f->head.htype == BM_FACE) {
ss->active_face_index.i == (intptr_t)f;
}
else {
ss->active_face_index.i = SCULPT_REF_NONE;
}
}
/* Update average stroke position. */
copy_v3_v3(location, ss->cache->true_location);
mul_m4_v3(ob->obmat, location);

View File

@ -1822,7 +1822,7 @@ static void cloth_sort_constraints_for_tasks(SculptSession *ss,
MEM_SAFE_FREE(vthreads);
}
static void cloth_brush_satisfy_constraints_intern(SculptSession *ss,
ATTR_NO_OPT static void cloth_brush_satisfy_constraints_intern(SculptSession *ss,
Brush *brush,
SculptClothSimulation *cloth_sim,
SculptClothTaskData *task,