From 973ab436f07c652cb6aa13bedc351df06bce6561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 12 May 2020 13:21:17 +0200 Subject: Fix T76514: Invalid geometry in Alembic crashes Blender Even though {T76514} is caused by invalid geometry, and thus technically constitutes a bug in the software that created the Alembic file, I would like Blender not to crash on importing such a file. The error in the Alembic file consists of invalid mesh loops, where consecutive loops refer to the same vertex. The `BKE_mesh_validate()` can actually correct these errors, so this commit focuses on two things: - Letting Blender survive the situation until the mesh is loaded, and - Detecting the error so that `BKE_mesh_validate()` can be called only when necessary. This ensures there is only a minimal impact on performance when loading actually valid data. Differential Revision: https://developer.blender.org/D7703 Reviewed By: JacquesLucke --- source/blender/blenkernel/intern/mesh_validate.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'source/blender/blenkernel/intern/mesh_validate.c') diff --git a/source/blender/blenkernel/intern/mesh_validate.c b/source/blender/blenkernel/intern/mesh_validate.c index 3343d41b13c..f64ed609d18 100644 --- a/source/blender/blenkernel/intern/mesh_validate.c +++ b/source/blender/blenkernel/intern/mesh_validate.c @@ -1593,8 +1593,15 @@ void BKE_mesh_calc_edges(Mesh *mesh, bool update, const bool select) MLoop *l_prev = (l + (mp->totloop - 1)); int j; for (j = 0; j < mp->totloop; j++, l++) { - /* lookup hashed edge index */ - med_index = POINTER_AS_INT(BLI_edgehash_lookup(eh, l_prev->v, l->v)); + /* Lookup hashed edge index, if it's valid. */ + if (l_prev->v != l->v) { + med_index = POINTER_AS_INT(BLI_edgehash_lookup(eh, l_prev->v, l->v)); + } + else { + /* This is an invalid edge; normally this does not happen in Blender, but it can be part + * of an imported mesh with invalid geometry. See T76514. */ + med_index = 0; + } l_prev->e = med_index; l_prev = l; } -- cgit v1.2.3