Corrected resource leak when adding in EDIT mode

Patch D10035

Addon: Bolt Factory: Corrected resource leak when adding in EDIT mode

Adding a bolt while in edit mode would *replace* the current object's mesh data block with a new one, and then fail to remove the original mesh data block.

Now the original mesh is updated in-place, preserving its name and avoiding orphan data blocks.
This commit is contained in:
Robert Meerman 2022-02-14 17:55:45 +13:00 committed by Aaron Keith
parent a5587f5223
commit 201b8271b9
1 changed files with 6 additions and 9 deletions

View File

@ -449,17 +449,14 @@ class add_mesh_bolt(Operator, AddObjectHelper):
obj.data[prm] = getattr(self, prm)
if bpy.context.mode == "EDIT_MESH":
active_object = context.active_object
name_active_object = active_object.name
bpy.ops.object.mode_set(mode='OBJECT')
obj = context.edit_object
mesh = createMesh.Create_New_Mesh(self, context)
obj = object_utils.object_data_add(context, mesh, operator=self)
obj.select_set(True)
active_object.select_set(True)
bpy.ops.object.join()
context.active_object.name = name_active_object
bpy.ops.object.mode_set(mode='EDIT')
bm = bmesh.from_edit_mesh(obj.data) # Access edit mode's mesh data
bm.from_mesh(mesh) # Append new mesh data
bmesh.update_edit_mesh(obj.data) # Flush changes (update edit mode's view)
bpy.data.meshes.remove(mesh) # Remove temporary mesh
return {'FINISHED'}