IfcOpenShell:尝试 return 包含 ifcopenshell 对象及其相应形状的字典时出现段错误

IfcOpenShell: Segfault when trying to return a dictionary containing ifcopenshell objects and their corresponding shapes

我正在尝试从 ifc 文件中提取所有 IfcProduct 形状,然后 return 它们(及其相应的产品)到我程序的另一部分。问题是,当我尝试 return 包含那些具有相应形状的对象的字典时,程序退出并出现分段错误。调试时我看到数据保存在数据结构中,但在 returning 之后或尝试访问此字典中包含的数据时,调试器退出并出现段错误。

我通过 conda 及其 运行ning 在 ubuntu docker 虚拟机中安装了 ifcopenshell。

这是我正在尝试的代码 运行:

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

通过将 shape_entry 字典中的产品解析为字符串解决了我的代码中的问题。

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