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: