From 63d65f0c397db5faff191bcfc713ec8337357ec0 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Fri, 18 Feb 2022 18:44:25 +1100 Subject: [PATCH] Fix #2046. Fix crash if style was updated from an already loaded IFC dataset --- .../api/style/remove_surface_style.py | 2 +- .../api/style/test_remove_surface_style.py | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/style/remove_surface_style.py b/src/ifcopenshell-python/ifcopenshell/api/style/remove_surface_style.py index 3a5a0ddf34..da43861851 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/style/remove_surface_style.py +++ b/src/ifcopenshell-python/ifcopenshell/api/style/remove_surface_style.py @@ -37,7 +37,7 @@ class Usecase: to_delete.add(texture) for attribute in self.settings["style"]: - if isinstance(attribute, ifcopenshell.entity_instance): + if isinstance(attribute, ifcopenshell.entity_instance) and attribute.id(): to_delete.add(attribute) self.file.remove(self.settings["style"]) diff --git a/src/ifcopenshell-python/test/api/style/test_remove_surface_style.py b/src/ifcopenshell-python/test/api/style/test_remove_surface_style.py index e922a0ef76..2722a1de9a 100644 --- a/src/ifcopenshell-python/test/api/style/test_remove_surface_style.py +++ b/src/ifcopenshell-python/test/api/style/test_remove_surface_style.py @@ -23,7 +23,7 @@ import ifcopenshell.api class TestRemoveSurfaceStyle(test.bootstrap.IFC4): def test_removing_a_shading_style(self): - style = self.file.createIfcSurfaceStyleShading(SurfaceColour=self.file.createIfcColourRgb()) + style = self.file.createIfcSurfaceStyleShading(SurfaceColour=self.file.createIfcColourRgb(None, 1, 1, 1)) ifcopenshell.api.run("style.remove_surface_style", self.file, style=style) assert len(list(self.file)) == 0 @@ -39,3 +39,19 @@ class TestRemoveSurfaceStyle(test.bootstrap.IFC4): style = self.file.createIfcSurfaceStyleWithTextures(Textures=[texture]) ifcopenshell.api.run("style.remove_surface_style", self.file, style=style) assert len(list(self.file)) == 0 + + def test_removing_a_rendering_style(self): + style = self.file.createIfcSurfaceStyleRendering( + SurfaceColour=self.file.createIfcColourRgb(None, 1, 1, 1), + Transparency=0.0, + DiffuseColour=self.file.createIfcColourRgb(None, 1, 1, 1), + TransmissionColour=self.file.createIfcNormalisedRatioMeasure(0.5), + SpecularHighlight=self.file.createIfcSpecularRoughness(0.5), + ReflectanceMethod="NOTDEFINED", + ) + # See issue #2046, IfcOpenShell exhibits different behaviour - we can + # remove entity_instances() without an ID if we create them afresh, but + # will segfault if we load them stale. + g = ifcopenshell.file.from_string(self.file.wrapped_data.to_string()) + ifcopenshell.api.run("style.remove_surface_style", g, style=g.by_type("IfcSurfaceStyleRendering")[0]) + assert len(list(g)) == 0