From c55b578c9e1f4f5d03fbac01c7efa070e1d6970d Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Thu, 7 Jan 2021 13:32:36 +0100 Subject: Fix T84142: crash when mirroring hair emitted from vertices The hair mirroring code seems to expect that hair is emitted from faces. The PE_mirror_x contains the following expression: mirrorfaces[pa->num * 2]. This only makes sense when pa->num is a face index. The simplest short term solution is to disable the mirror operator when the particles haven't been emitted from faces. Diffferential Revision: https://developer.blender.org/D10002 --- source/blender/editors/physics/particle_edit.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'source/blender/editors/physics') diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index ff36197c61e..8ab25fa74b8 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -3496,6 +3496,21 @@ static int mirror_exec(bContext *C, wmOperator *UNUSED(op)) return OPERATOR_FINISHED; } +static bool mirror_poll(bContext *C) +{ + if (!PE_hair_poll(C)) { + return false; + } + + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); + Scene *scene = CTX_data_scene(C); + Object *ob = CTX_data_active_object(C); + PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); + + /* The operator only works for hairs emitted from faces. */ + return edit->psys->part->from == PART_FROM_FACE; +} + void PARTICLE_OT_mirror(wmOperatorType *ot) { /* identifiers */ @@ -3505,7 +3520,7 @@ void PARTICLE_OT_mirror(wmOperatorType *ot) /* api callbacks */ ot->exec = mirror_exec; - ot->poll = PE_hair_poll; + ot->poll = mirror_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; -- cgit v1.2.3