Fix T68135: Do not return NULL/None when converting an object to a mesh.
Does not make sense in the use-cases of that function, especially since we don't know whether it is actually due to an error, or some glitch (like an empty curve). Think we always want to get a mesh when using either operator conversion, or the `bpy.data.meshes.new_from_object` function. Note that an assert was also added to ensure we do try to convert from a valid 'geometry' object type.
This commit is contained in:
parent
dda0de4a3d
commit
26d5fae284
Notes:
blender-bot
2023-02-14 09:29:42 +01:00
Referenced by issue #68135, Empty curve object crashes export
|
@ -224,7 +224,9 @@ struct Mesh *BKE_mesh_new_from_object(struct Depsgraph *depsgraph,
|
|||
struct Object *object,
|
||||
bool preserve_all_data_layers);
|
||||
|
||||
/* This is a version of BKE_mesh_new_from_object() which stores mesh in the given main database. */
|
||||
/* This is a version of BKE_mesh_new_from_object() which stores mesh in the given main database.
|
||||
* However, that function enforces object type to be a geometry one, and ensures a mesh is always
|
||||
* generated, be it empty. */
|
||||
struct Mesh *BKE_mesh_new_from_object_to_bmain(struct Main *bmain,
|
||||
struct Depsgraph *depsgraph,
|
||||
struct Object *object,
|
||||
|
|
|
@ -1216,10 +1216,14 @@ Mesh *BKE_mesh_new_from_object_to_bmain(Main *bmain,
|
|||
Object *object,
|
||||
bool preserve_all_data_layers)
|
||||
{
|
||||
BLI_assert(ELEM(object->type, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_MESH));
|
||||
|
||||
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;
|
||||
/* Unable to convert the object to a mesh, return an empty one. */
|
||||
Mesh *mesh_in_bmain = BKE_mesh_add(bmain, ((ID *)object->data)->name + 2);
|
||||
id_us_min(&mesh_in_bmain->id);
|
||||
return mesh_in_bmain;
|
||||
}
|
||||
|
||||
/* Make sure mesh only points original datablocks, also increase users of materials and other
|
||||
|
|
Loading…
Reference in New Issue