diff options
author | Robert Meerman <meermanr> | 2022-02-14 07:55:45 +0300 |
---|---|---|
committer | Aaron Keith <aaroninusa@gmail.com> | 2022-02-14 07:55:45 +0300 |
commit | 201b8271b907bdc0b2ebcee740dc1fa98e832fd4 (patch) | |
tree | e4099d425ff9f730629cf80289237de9f6783885 | |
parent | a5587f5223f65843e7d4c52088d782e3075a0df7 (diff) |
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.
-rw-r--r-- | add_mesh_BoltFactory/Boltfactory.py | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/add_mesh_BoltFactory/Boltfactory.py b/add_mesh_BoltFactory/Boltfactory.py index 501043d1..0c56e9b7 100644 --- a/add_mesh_BoltFactory/Boltfactory.py +++ b/add_mesh_BoltFactory/Boltfactory.py @@ -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'} |