[Bf-blender-cvs] [b39d7e484c6] master: Fix T66631: Crash when converting objects from Curve to Mesh
Sybren A. Stüvel
noreply at git.blender.org
Wed Jul 10 14:14:53 CEST 2019
Commit: b39d7e484c6be45fb8ffe0809aecb5726b7d1936
Author: Sybren A. Stüvel
Date: Wed Jul 10 12:58:39 2019 +0200
Branches: master
https://developer.blender.org/rBb39d7e484c6be45fb8ffe0809aecb5726b7d1936
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
===================================================================
M source/blender/blenkernel/intern/mesh_convert.c
M source/blender/editors/object/object_add.c
===================================================================
diff --git a/source/blender/blenkernel/intern/mesh_convert.c b/source/blender/blenkernel/intern/mesh_convert.c
index dd36da44b92..fec83ebc899 100644
--- a/source/blender/blenkernel/intern/mesh_convert.c
+++ b/source/blender/blenkernel/intern/mesh_convert.c
@@ -1048,6 +1048,7 @@ static Mesh *mesh_new_from_curve_type_object(Object *object)
/* BKE_mesh_from_nurbs changes the type to a mesh, check it worked. If it didn't the curve did
* not have any segments or otherwise would have generated an empty mesh. */
if (temp_object->type != OB_MESH) {
+ BKE_id_free(NULL, temp_object->data);
BKE_id_free(NULL, temp_object);
return NULL;
}
@@ -1216,6 +1217,10 @@ Mesh *BKE_mesh_new_from_object_to_bmain(Main *bmain,
bool preserve_all_data_layers)
{
Mesh *mesh = BKE_mesh_new_from_object(depsgraph, object, preserve_all_data_layers);
+ if (mesh == NULL) {
+ /* Unable to convert the object to a mesh. */
+ return NULL;
+ }
/* Make sure mesh only points original datablocks, also increase users of materials and other
* possibly referenced data-blocks.
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);
}
More information about the Bf-blender-cvs
mailing list