# How to remove dead BMVerts from a list?

I am trying to fix a bug in my script that happens in rare instances. I believe the bug occurs due to the very last thing the script is doing, which is:

bmesh.ops.remove_doubles(bm, verts=verts_to_weld, dist=0.001)


I think the problem is that verts_to_weld refers to a list of BMVerts that contains dead elements. This is because earlier in the script I use bmesh.ops.delete() to get rid of inner faces after using bmesh.ops.extrude_face_region(). So essentially my Remove Doubles is referring to some vertices that have been deleted earlier and don't exist in my bmesh anymore, but are still in the list. Is there a way to take the list verts_to_weld and remove any dead verts from that list? Thanks! Here's what my error looks like and also the print(verts_to_weld) at the bottom:

Look at the is_valid property of a bmesh element.

In this case you have verts in your list that are no longer valid. Use BMVert.is_valid to check.

Try

bmesh.ops.remove_doubles(bm,
verts=[v for v in verts_to_weld if v.is_valid],
dist=0.001)


From the print output, it looks like the 'dead' vertices don't have any index associated with them. Did you try iterating through the list - verts_to_weld - and removing vertices with index == None? Or maybe print the index of all the vertices in the list and see what it is for dead vertices. Most likely it won't be an int.

• Very, very unlikely an int property is no longer an int. See the documentation BMVert.index Dead bmesh elements are marked as invalid eg is_dead = not vert.is_valid – batFINGER Oct 16 '18 at 11:36
• @batFinger I tried checking the is_valid flag of the deleted verts. But they had it set to True. That's the reason I thought it could be determined through the index. Maybe I missed something while making the delete call. – Blender Dadaist Oct 16 '18 at 14:00
• The v.is_valid works perfectly for me. – z01ks Oct 17 '18 at 0:26
• @z01ks Glad to know that :) – Blender Dadaist Oct 17 '18 at 4:30