Bmesh: Immediately encounter strange error after adding new layer and running bmesh op

The script is simple:

import bpy, bmesh

mesh = bpy.context.edit_object.data
bm = bmesh.from_edit_mesh(mesh)
geom = [e for e in bm.verts[:] + bm.edges[:] + bm.faces[:] if e.select]

cut_layer = bm.edges.layers.int.new('cut')
ret = bmesh.ops.bisect_plane(bm, geom=geom , plane_co=(0,1,0), plane_no=(0, 1, 0))
bm.edges.layers.int.remove(cut_layer)

bmesh.update_edit_mesh(mesh)


I get the error:

TypeError: geom: 8 BMEdge has been removed


Here's an example blend file:

Can anyone explain what's going wrong here? I know the function itself looks a little pointless but that's because I've boiled the problem down to it's simplest form. Why does the operation have a problem with the new edge layer I've added? I can't find anything online about this...

Assign your int layer before you assign geometry. PS took out verts from bisectable geometry.

import bpy, bmesh

mesh = bpy.context.edit_object.data
bm = bmesh.from_edit_mesh(mesh)
cut_layer = bm.edges.layers.int.new('cut')
geom = [e for e in bm.edges[:] + bm.faces[:] if e.select]

ret = bmesh.ops.bisect_plane(bm, geom=geom , plane_co=(0,1,0), plane_no=(1, 0, 0))
bm.edges.layers.int.remove(cut_layer)

bmesh.update_edit_mesh(mesh)

• This is a bit of a problem as I'm creating my own bmesh operations as it were, which make no reference to selected elements, but receive parameters as lists of geometry (just like the built-in bmesh ops). Is there some way I can keep the order of my original code while fixing the problem? Even if it means iterating over all the input geom after adding the new layer. – hedgehog90 Mar 12 '17 at 12:40