From bf1475770986d411d8b8036d9097745d80b37242 Mon Sep 17 00:00:00 2001 From: Joseph Eagar Date: Sat, 17 Sep 2022 01:47:14 -0700 Subject: Sculpt: Fix memory corruption with reading masks from PBVH_BMESH Feeding -1 to BM_ELEM_CD_GET_VOID_P will not return NULL. --- source/blender/editors/sculpt_paint/sculpt.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'source/blender/editors') diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 1f64a2445aa..688573d78a6 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -250,15 +250,16 @@ void SCULPT_vertex_persistent_normal_get(SculptSession *ss, PBVHVertRef vertex, float SCULPT_vertex_mask_get(SculptSession *ss, PBVHVertRef vertex) { - BMVert *v; - float *mask; switch (BKE_pbvh_type(ss->pbvh)) { case PBVH_FACES: return ss->vmask ? ss->vmask[vertex.i] : 0.0f; - case PBVH_BMESH: + case PBVH_BMESH: { + BMVert *v; + int cd_mask = CustomData_get_offset(&ss->bm->vdata, CD_PAINT_MASK); + v = (BMVert *)vertex.i; - mask = BM_ELEM_CD_GET_VOID_P(v, CustomData_get_offset(&ss->bm->vdata, CD_PAINT_MASK)); - return mask ? *mask : 0.0f; + return cd_mask != -1 ? BM_ELEM_CD_GET_FLOAT(v, cd_mask) : 0.0f; + } case PBVH_GRIDS: { const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh); const int grid_index = vertex.i / key->grid_area; -- cgit v1.2.3