The following python operator crashes blender. I'm using 2.93.5 on Win10.
Strangely however, if I use the python terminal built into blender I can import bpy, bmesh
and from bmesh.types import BMVert
and then paste the entire code between ### START ###
and ### END ###
and it all works fine, with no crash.
But when I try to run the code from the python terminal by typing bpy.ops.mesh.generate_arms()
then blender will immediately crash.
Is there something wrong with the code, or is this something I should file a bug report for blender?
import bpy, bmesh
from bmesh.types import BMVert
class MESH_OT_Generate_Arms(bpy.types.Operator):
"""Generate Arms"""
bl_idname = "mesh.generate_arms"
bl_label = "Generate Arms"
def execute(self, context):
### START ###
#create cube
bpy.ops.mesh.primitive_cube_add(size=0.1)
# turn on edit mode
bpy.ops.object.mode_set(mode='EDIT')
# get the mesh data of the active object
ao_d = context.active_object.data
# get bmesh from ao_d
bm = bmesh.from_edit_mesh(ao_d)
bm.faces.ensure_lookup_table()
# extrude
ext = bmesh.ops.extrude_face_region(bm, geom=[bm.faces[1]])
# translate
bmesh.ops.translate(bm, vec=(0, 1, 0), verts=[v for v in ext["geom"] if isinstance(v, BMVert)])
bm.normal_update()
# update the viewport so we can see what we are doing
bmesh.update_edit_mesh(ao_d, True, True)
# return to object mode
bpy.ops.object.mode_set(mode='OBJECT')
### END ###
return {'FINISHED'}
def register():
bpy.utils.register_class(MESH_OT_Generate_Arms)
def unregister():
bpy.utils.unregister_class(MESH_OT_Generate_Arms)
if __name__ == '__main__':
register()
Here is a screenshot of just cutting and pasting the text in the terminal, showing that it works fine. It only crashes when I run it in the terminal with bpy.ops.mesh.generate_arms()
It still immediately crashes blender when I run bpy.ops.mesh.generate_arms()
in the terminal.
It also immediately crashes blender if I search with F3, and then click "Generate Arms" to run it that way.
# extrude
because I commented out the file line by line, testing each time if it would crash, starting from the bottom, and it continued to crash until I commented out that line. But I have no idea why that line might be cause it to crash. $\endgroup$