I've made a lot of scripts that had this error: ReferenceError: BMesh data of type BMesh has been removed
. While I've usually found workarounds I would like to know what causes this error and how to fix it for future scripts.
Edit: This is my fence.
import bpy
import bmesh
class Create():
mesh = bpy.context.active_object
bm = bmesh.from_edit_mesh(mesh.data)
def Verts(self,pose):
self.bm.verts.ensure_lookup_table()
self.bm.verts.new((1,1,1))
bmesh.update_edit_mesh(self.mesh.data
class Modal(bpy.types.Operator):
bl_idname = "object.modal"
bl_label = "Modal Op"
bl_description = "Other thingy"
bl_options = {"REGISTER"}
@classmethod
def poll(cls, context):
return True
def invoke(self, context, event):
bpy.ops.object.mode_set(mode='EDIT')
context.window_manager.modal_handler_add(self)
return {"RUNNING_MODAL"}
def modal(self, context, event):
c = Create()
if event.type == "LEFTMOUSE" and event.value == "PRESS":
c.Verts((0,0,1))
print("Test")
if event.type in {"RIGHTMOUSE", "ESC"}:
return {"CANCELLED"}
keys = ["WHEELUPMOUSE","WHEELDOWNMOUSE","MIDDLEMOUSE","LEFTMOUSE"]
for i in keys:
if event.type == i:
return{"PASS_THROUGH"}
return {"RUNNING_MODAL"}
def register():
bpy.utils.register_class(Modal)
def unregister():
bpy.utils.unregister_class(Modal)
if __name__ == "__main__":
register()
bmesh.from_edit_mesh(me)
, and then toggling object mode. $\endgroup$context.mode != 'EDIT_MESH'
. $\endgroup$