From d5bca524d55d929a9e725a51b373de4804e1fe2e Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Fri, 5 Jun 2015 12:56:56 +0200 Subject: Fix T44960: Crash with 'Shape Cut' in edit hair mode. This is only supported for mesh objects so far. Also, abort in case there are no faces in dm (instead of crashing on NULL BVH tree...). --- source/blender/editors/physics/particle_edit.c | 18 +++++++++++------- source/blender/makesrna/intern/rna_sculpt_paint.c | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'source') diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index 7abd6f4c8ef..f25679986a5 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -414,18 +414,18 @@ static void PE_set_view3d_data(bContext *C, PEData *data) } } -static void PE_create_shape_tree(PEData *data, Object *shapeob) +static bool PE_create_shape_tree(PEData *data, Object *shapeob) { DerivedMesh *dm = shapeob->derivedFinal; memset(&data->shape_bvh, 0, sizeof(data->shape_bvh)); if (!dm) { - return; + return false; } DM_ensure_tessface(dm); - bvhtree_from_mesh_faces(&data->shape_bvh, dm, 0.0f, 4, 8); + return bvhtree_from_mesh_faces(&data->shape_bvh, dm, 0.0f, 4, 8); } static void PE_free_shape_tree(PEData *data) @@ -4059,11 +4059,12 @@ void PARTICLE_OT_brush_edit(wmOperatorType *ot) static int shape_cut_poll(bContext *C) { if (PE_hair_poll(C)) { - Scene *scene= CTX_data_scene(C); - ParticleEditSettings *pset= PE_settings(scene); + Scene *scene = CTX_data_scene(C); + ParticleEditSettings *pset = PE_settings(scene); - if (pset->shape_object) + if (pset->shape_object && (pset->shape_object->type == OB_MESH)) { return true; + } } return false; @@ -4179,7 +4180,10 @@ static int shape_cut_exec(bContext *C, wmOperator *UNUSED(op)) int removed; PE_set_data(C, &data); - PE_create_shape_tree(&data, shapeob); + if (!PE_create_shape_tree(&data, shapeob)) { + /* shapeob may not have faces... */ + return OPERATOR_CANCELLED; + } if (selected) foreach_selected_point(&data, shape_cut); diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c index d5e99d4f3e9..7b30aa84cfb 100644 --- a/source/blender/makesrna/intern/rna_sculpt_paint.c +++ b/source/blender/makesrna/intern/rna_sculpt_paint.c @@ -871,6 +871,7 @@ static void rna_def_particle_edit(BlenderRNA *brna) prop = RNA_def_property(srna, "shape_object", PROP_POINTER, PROP_NONE); RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Shape Object", "Outer shape to use for tools"); + RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_Mesh_object_poll"); RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_ParticleEdit_redo"); /* brush */ -- cgit v1.2.3