From 416a572664d031a2e99f1ecf7da55ea822ab53cf Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 23 Oct 2023 15:24:43 +0500 Subject: [PATCH] switch_representation not to break with temporary mesh representations I've found a bug that if you have some object that consists of extrusion and can be edited in profile edit mode, when you finish editing, it would remove the type object (and I guess the other occurences objects). It happened because during edit mode it's using temporary mesh data and `switch_representation` would replace this temp mesh data with new representation and remove the old mesh data that might still used by the other occurences and the type. The issue also was leading to a crash during `box.template_icon(icon_value=AuthoringData.data["type_thumbnail"], scale=5)` if you had BIM Tool thumbnail preview opened in the process - removing type object would make thumbnail icon become invalid leading to the crash. Crash mentioned here: https://community.osarch.org/discussion/1753/bbim-two-door-types-with-connected-properties --- src/blenderbim/blenderbim/core/geometry.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/blenderbim/blenderbim/core/geometry.py b/src/blenderbim/blenderbim/core/geometry.py index 54dbeeb49d..7f91fd15bc 100644 --- a/src/blenderbim/blenderbim/core/geometry.py +++ b/src/blenderbim/blenderbim/core/geometry.py @@ -104,6 +104,7 @@ def switch_representation( return entity = ifc.get_entity(obj) + current_obj_data = obj.data # doesn't resolve mapped representations in case if it's going to have openings # otherwise we would also add openings to the type and other occurences mesh data @@ -125,6 +126,10 @@ def switch_representation( # we assume that all the occurences and the type have the same representation context active # so geometry.delete_data cannot remove the data that's still used by some other object if should_reload and old_repr_data: + # if current object was using some temporary mesh (like during profile edit mode) instead of `old_repr_data` + # then `change_object_data` won't switch the mesh for all the occurences and we need to do it explicitly + if current_obj_data != old_repr_data and old_repr_data.users: + geometry.replace_object_data_globally(old_repr_data, new_repr_data) geometry.delete_data(old_repr_data) geometry.clear_modifiers(obj)