Even though T76514: Invalid geometry in Alembic crashes Blender is caused by invalid geometry, and thus a bug in SpeedTree, 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 patch 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.
An alternative approach would be to detect the invalid loops while loading the Alembic data, and skipping the invalid faces. The current mesh reading code is already not the simplest, though, and adding the required conditions to it would also make things like the mesh datastructure allocation more complex. Adding one extra safety, one simple check, and then deferring to existing error checking+fixing code seemed like a better approach.