diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2019-07-10 13:58:39 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2019-07-10 15:13:42 +0300 |
commit | b39d7e484c6be45fb8ffe0809aecb5726b7d1936 (patch) | |
tree | 468e0c92b102f06b3736ea0f85ba0395fbac9d29 /source/blender/editors | |
parent | d3e1782abc3be15fdc45e5139ebe1e9638d52734 (diff) |
Fix T66631: Crash when converting objects from Curve to Mesh
When `BKE_mesh_new_from_object()` cannot convert an object to a mesh, it
returns `NULL`. This case was not handled at all in
`BKE_mesh_new_from_object_to_bmain()` or `curvetomesh()`, causing a
segmentation fault.
This commit fixes the segmentation fault, and leaves the curve object as
a curve object.
Reviewed By: mont29, brecht, sergey
Differential Revision: https://developer.blender.org/D5217
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/object/object_add.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 51b40a968ed..f8cf55933aa 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -2036,7 +2036,13 @@ static void curvetomesh(Main *bmain, Depsgraph *depsgraph, Object *ob) { Object *object_eval = DEG_get_evaluated_object(depsgraph, ob); Curve *curve = ob->data; + Mesh *mesh = BKE_mesh_new_from_object_to_bmain(bmain, depsgraph, object_eval, true); + if (mesh == NULL) { + /* Unable to convert the curve to a mesh. */ + return; + } + BKE_object_free_modifiers(ob, 0); /* Replace curve used by the object itself. */ ob->data = mesh; @@ -2125,7 +2131,7 @@ static Base *duplibase_for_convert( static int convert_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); Base *basen = NULL, *basact = NULL; @@ -2344,8 +2350,9 @@ static int convert_exec(bContext *C, wmOperator *op) BKE_curve_curve_dimension_update(cu); if (target == OB_MESH) { + /* No assumption should be made that the resulting objects is a mesh, as conversion can + * fail. */ curvetomesh(bmain, depsgraph, newob); - /* meshes doesn't use displist */ BKE_object_free_curve_cache(newob); } @@ -2368,8 +2375,9 @@ static int convert_exec(bContext *C, wmOperator *op) newob = ob; } + /* No assumption should be made that the resulting objects is a mesh, as conversion can + * fail. */ curvetomesh(bmain, depsgraph, newob); - /* meshes doesn't use displist */ BKE_object_free_curve_cache(newob); } |