Page MenuHome

Creating a new layer in bmesh invalidates old geometry references - should be mentioned in documentation
Closed, InvalidPublic

Description

import bpy, bmesh

mesh = bpy.context.edit_object.data
bm = bmesh.from_edit_mesh(mesh)
edges1 = set(bm.edges[:])
print(edges1)
print("")
cut_layer = bm.edges.layers.int.new('cut')
edges2 = set(bm.edges[:])
print(edges1)
print("")
print(edges2)
print("")
print(edges1 == edges2)

The second instance of print(edges1) outputs a load of dead BMEdges.
I've just run into this problem and it would have been very helpful if this was mentioned somewhere in the documenatation, under the new() method in BMLayerCollection.
You get a very non-descript error if you try and work on the dead geometry, it took me a while to work it out.

Details

Type
To Do

Event Timeline

Bastien Montagne (mont29) closed this task as Invalid.
Bastien Montagne (mont29) claimed this task.

Rule of thumb in blender: never keep references of actual data in py, blender may invalidate them at any time. This is true for ID datablocks themselves, as well as lower-level data. Nothing wrong here, and certainly not a bug!