簡體   English   中英

IfcOpenShell:嘗試返回包含 ifcopenshell 對象及其相應形狀的字典時出現段錯誤

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

我試圖從 ifc 文件中提取所有 IfcProduct 形狀並將它們(及其相應的產品)返回到我程序的另一部分。 問題是,當我嘗試返回包含具有相應形狀的那些對象的字典時,程序會以分段錯誤退出。 在調試時,我看到數據保存在數據結構中,但在返回后或嘗試訪問此 dict 中包含的數據時,調試器以段錯誤退出。

我通過 conda 安裝了 ifcopenshell 並在 ubuntu docker vm 中運行。

這是我試圖運行的代碼:

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}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM