im trying to extract all the IfcProduct-shapes from a ifc file and return them (with their corresponding Product) to another part of my program. The problem is that when i try to return a dictionary containing those objects with their corresponding shapes, the program exits with a segmentation fault. While debugging i saw that the data is saved in the data structure but right after returning or while trying to access the data contained in this dict, the debugger exits with a segfault.

I installed ifcopenshell via conda and its running in a ubuntu docker vm.

This is the code im trying to run:

def create_shapes_from_ifcopenshell_object(ifcopenshell_object) -> dict:
"""Creates a shape from the given IfcOpenShell Object and returns a dictionary containing the GlobalId as the key
and the product and shape as dictionary."""
try:
    print("Creating shape-objects from IfcProducts.")
    settings = ifcopenshell.geom.settings()
    products = ifcopenshell_object
    product_shapes_dict = {}
    for product in products:
        if product.is_a("IfcOpeningElement") or product.is_a("IfcSite") or product.is_a("IfcAnnotation"):
            continue
        if product.Representation is not None:
            try:
                shape = ifcopenshell.geom.create_shape(settings, product).geometry
            except Exception as e:
                print(str(e) + ". Product:" + str(product))
                continue
            shape_entry = {"guid": product.GlobalId,
                           "product": product,
                           "shape": shape}
            product_shapes_dict[shape_entry["guid"]] = shape_entry
except RuntimeError as re:
    print("Runtime error" + str(re))
    return {"ERROR": str(e)}
except Exception as e:
    print("ERROR during shape creation.")
    return {"ERROR": str(e)}
# pprint(product_shapes_dict) <-- THIS SHOWS THE CORRECT DICT
return product_shapes_dict # <-- Segfault directly after this
1

There are 1 answers

0
j-wala On BEST ANSWER

Fixed the problem in my code by parsing the product in the shape_entry dictionary to a string.

shape_entry = {"guid": product.GlobalId,
                     "product": str(product),
                     "shape": shape}