From c121ff37cfc0d375cadc78ba78baf43195c8d65d Mon Sep 17 00:00:00 2001 From: Radionic Date: Thu, 28 Sep 2023 18:48:52 +0800 Subject: [PATCH] fix: occasional segmentation fault --- blender/ops_join.py | 12 +++++------- global_bpy.py | 44 +++++++++++++++++++++++--------------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/blender/ops_join.py b/blender/ops_join.py index 996fd7b..557e805 100644 --- a/blender/ops_join.py +++ b/blender/ops_join.py @@ -9,13 +9,11 @@ class Mesh_JoinMesh(blender_node.ObjectOps): CUSTOM_NAME = "Join Meshes" def blender_process(self, bpy, BPY_OBJ, **props): - - prop_values = props.values() - - override = bpy.context.copy() - override["active_object"] = BPY_OBJ - override["selected_editable_objects"] = list(prop_values) + [BPY_OBJ] - bpy.ops.object.join(override) + prop_values = props.values() + for obj in list(prop_values) + [BPY_OBJ]: + obj.select_set(True) + bpy.context.view_layer.objects.active = BPY_OBJ + bpy.ops.object.join() return (BPY_OBJ,) diff --git a/global_bpy.py b/global_bpy.py index af93e24..b24cd60 100644 --- a/global_bpy.py +++ b/global_bpy.py @@ -1,37 +1,39 @@ import bpy global_bpy = bpy -def get_bpy(): + +def get_bpy(): global global_bpy return global_bpy + def reset_bpy(): global global_bpy bpy = global_bpy # not using this cause this cause seg fault frequently - # global_bpy.ops.wm.read_factory_settings(use_empty=True) + bpy.ops.wm.read_factory_settings(use_empty=True) - # check if there's no object, return - if len(bpy.data.objects) == 0: - return + # # check if there's no object, return + # if len(bpy.data.objects) == 0: + # return - # enter object mode - if bpy.context.mode != 'OBJECT': - bpy.ops.object.mode_set(mode='OBJECT') + # # enter object mode + # if bpy.context.mode != 'OBJECT': + # bpy.ops.object.mode_set(mode='OBJECT') - # Delete all objects - bpy.ops.object.select_all(action='DESELECT') - bpy.ops.object.select_all(action='SELECT') - bpy.ops.object.delete() + # # Delete all objects + # bpy.ops.object.select_all(action='DESELECT') + # bpy.ops.object.select_all(action='SELECT') + # bpy.ops.object.delete() - # Delete all meshes - for mesh in bpy.data.meshes: - bpy.data.meshes.remove(mesh) + # # Delete all meshes + # for mesh in bpy.data.meshes: + # bpy.data.meshes.remove(mesh) - # Delete all materials - for material in bpy.data.materials: - bpy.data.materials.remove(material) + # # Delete all materials + # for material in bpy.data.materials: + # bpy.data.materials.remove(material) - # Delete all textures - for texture in bpy.data.textures: - bpy.data.textures.remove(texture) \ No newline at end of file + # # Delete all textures + # for texture in bpy.data.textures: + # bpy.data.textures.remove(texture)