From 4d0be197205a1a1254fcec2376bc58f82a0293b8 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 29 Jun 2023 14:56:06 +0500 Subject: [PATCH] Fix crash on Mac M1 on removing cost item Crash happened because we were addressing `.id()` of already deleted `cost_item`. Surprisingly for me on windows addressing `cost_item` was causing crash too but `cost_item.id()` worked fine. --- src/blenderbim/blenderbim/bim/module/cost/operator.py | 2 +- src/blenderbim/blenderbim/core/cost.py | 5 +++-- src/blenderbim/blenderbim/tool/cost.py | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/cost/operator.py b/src/blenderbim/blenderbim/bim/module/cost/operator.py index 320e3840f7..02c7b2e9a8 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/operator.py +++ b/src/blenderbim/blenderbim/bim/module/cost/operator.py @@ -163,7 +163,7 @@ class RemoveCostItem(bpy.types.Operator, tool.Ifc.Operator): cost_item: bpy.props.IntProperty() def _execute(self, context): - core.remove_cost_item(tool.Ifc, tool.Cost, cost_item=tool.Ifc.get().by_id(self.cost_item)) + core.remove_cost_item(tool.Ifc, tool.Cost, cost_item_id=self.cost_item) class EnableEditingCostItem(bpy.types.Operator, tool.Ifc.Operator): diff --git a/src/blenderbim/blenderbim/core/cost.py b/src/blenderbim/blenderbim/core/cost.py index 4cc4db3d5b..e0afbe999e 100644 --- a/src/blenderbim/blenderbim/core/cost.py +++ b/src/blenderbim/blenderbim/core/cost.py @@ -59,9 +59,10 @@ def contract_cost_items(cost): cost.load_cost_schedule_tree() -def remove_cost_item(ifc, cost, cost_item): +def remove_cost_item(ifc, cost, cost_item_id): + cost_item = ifc.get().by_id(cost_item_id) ifc.run("cost.remove_cost_item", cost_item=cost_item) - cost.clean_up_cost_item_tree(cost_item) + cost.clean_up_cost_item_tree(cost_item_id) cost.load_cost_schedule_tree() diff --git a/src/blenderbim/blenderbim/tool/cost.py b/src/blenderbim/blenderbim/tool/cost.py index f007e6ff01..aef65f093c 100644 --- a/src/blenderbim/blenderbim/tool/cost.py +++ b/src/blenderbim/blenderbim/tool/cost.py @@ -96,11 +96,11 @@ class Cost(blenderbim.core.tool.Cost): props.contracted_cost_items = json.dumps(cls.contracted_cost_items) @classmethod - def contract_cost_item(cls, cost_item): + def contract_cost_item(cls, cost_item_id): props = bpy.context.scene.BIMCostProperties if not hasattr(cls, "contracted_cost_items"): cls.contracted_cost_items = json.loads(props.contracted_cost_items) - cls.contracted_cost_items.append(cost_item.id()) + cls.contracted_cost_items.append(cost_item_id) props.contracted_cost_items = json.dumps(cls.contracted_cost_items) @classmethod @@ -114,11 +114,11 @@ class Cost(blenderbim.core.tool.Cost): props.contracted_cost_items = json.dumps(cls.contracted_cost_items) @classmethod - def clean_up_cost_item_tree(cls, cost_item): + def clean_up_cost_item_tree(cls, cost_item_id): props = bpy.context.scene.BIMCostProperties if not hasattr(cls, "contracted_cost_items"): cls.contracted_cost_items = json.loads(props.contracted_cost_items) - if props.active_cost_item_id == cost_item.id(): + if props.active_cost_item_id == cost_item_id: props.active_cost_item_id = 0 if props.active_cost_item_index in cls.contracted_cost_items: cls.contracted_cost_items.remove(props.active_cost_item_index)