Page MenuHome

Blender crashes when invalid edges are defined and switching to edit mode
Closed, ArchivedPublic

Description

System Information
Operating system: Linux Mint
Graphics card: GeForce RTX 2060 Super

Blender Version
Broken: 2.92.0
Worked: unknown

Short description of error

Blender crashes when an object with invalid edges is created and then switching to edit mode.

  • Expected behavior ***

It should not be possible to add a edges with invalid indices. Does checking this create a performance loss that is too big? At least the edit mode should not crash when such edges are Trying to be accessed. After all the object mode also seems to be handling this fine.

Exact steps for others to reproduce the error

# Start Blender (2.92.0) and run this script

import bpy
from math import cos, sin

# Clean up
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()

# Create mesh
vertices = [[0,0,0],[1,1,0],[2,2,0]]
# There is one additional edge in here!
edges = [[0,1],[1,2],[2,3]]
faces = []

mesh = bpy.data.meshes.new('object')
obj = bpy.data.objects.new(mesh.name, mesh)
mesh.from_pydata(vertices, edges, faces)
bpy.context.scene.collection.objects.link(obj)
obj.select_set(state=True)
bpy.context.view_layer.objects.active = obj

# Now press TAB to go to edit mode and make Blender crash
# (sometimes need to wait a bit or press several times)

Event Timeline

Philipp Oeser (lichtwerk) closed this task as Archived.Wed, May 5, 1:37 PM

From https://docs.blender.org/api/master/bpy.types.Mesh.html#bpy.types.Mesh.from_pydata

Warning
Invalid mesh data (out of range indices, edges with matching indices, 2 sided faces… etc) are not prevented. If the data used for mesh creation isn’t known to be valid, run Mesh.validate after this function.

so insterting

mesh.validate()

after

mesh.from_pydata(vertices, edges, faces)

will check (and clean up) the mesh, thus preventing the crash.

This is not considered a bug, it is documented behavior.
Thx reporting, but will have to close.