Title: Segfault when batch-deleting an IFC aggregate and its decomposed parts · Issue #9299 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: Segfault when batch-deleting an IFC aggregate and its decomposed parts · Issue #9299 · IfcOpenShell/IfcOpenShell
X Title: Segfault when batch-deleting an IFC aggregate and its decomposed parts · Issue #9299 · IfcOpenShell/IfcOpenShell
Description: Bug Description Environment os: Linux (Linux Mint 22.3, kernel 6.14.0-37-generic, glibc 2.39) os_version: #37~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC python_version: 3.13.13 architecture: x86_64 blender_version: 5.2.0 LTS bonsai_version: 0.8....
Open Graph Description: Bug Description Environment os: Linux (Linux Mint 22.3, kernel 6.14.0-37-generic, glibc 2.39) os_version: #37~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC python_version: 3.13.13 architecture: x86_64 blender...
X Description: Bug Description Environment os: Linux (Linux Mint 22.3, kernel 6.14.0-37-generic, glibc 2.39) os_version: #37~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC python_version: 3.13.13 architecture: x86_64 blender...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/issues/9299
X: @github
Domain: github.com
IPv4 address: 140.82.112.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Segfault when batch-deleting an IFC aggregate and its decomposed parts","articleBody":"### Bug Description\n\n**Environment**\n\n- os: Linux (Linux Mint 22.3, kernel 6.14.0-37-generic, glibc 2.39)\n- os_version: `#37~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC`\n- python_version: 3.13.13\n- architecture: x86_64\n- blender_version: 5.2.0 LTS\n- bonsai_version: `0.8.6a260813` (alpha build from commit\n `1af5cc9bbe5e81814e1fb744f6fa77b41ba869b2`, installed via the Blender\n extension manager — a Blender extension, not bundled)\n\n**Description**\n\nDeleting an IFC aggregate (e.g. an `IfcStair`) **together with its\nparts** (`IfcStairFlight`, `IfcSlab`) in a single\n`bim.override_object_delete` batch closes Blender with a native\nsegfault. The crash is a C++ fault (`__dynamic_cast`) inside the\nifcopenshell binding layer; it is *not* a catchable Python exception,\nso Blender exits entirely and any unsaved work is lost.\n\n**Suspected cause**\n\n`OverrideDelete.track_aggregates()` retains live\n`ifcopenshell.entity_instance` objects *before* the deletion loop. When\nan aggregate is also selected, `remove_product` can remove its backing\nIFC entity during that loop. `delete_empty_aggregates()` later calls\n`.id()` on the retained wrapper, which can dereference an invalid native\nentity and segfault before Python can raise or handle an exception.\n\nReferences (at commit `1af5cc9`):\n\n- [operator.py L895](https://github.com/IfcOpenShell/IfcOpenShell/blob/1af5cc9bbe5e81814e1fb744f6fa77b41ba869b2/src/bonsai/bonsai/bim/module/geometry/operator.py#L895)\n — `aggregates_to_check = self.track_aggregates(objects_to_remove)`\n (wrappers snapshotted before deletion)\n- [operator.py L989](https://github.com/IfcOpenShell/IfcOpenShell/blob/1af5cc9bbe5e81814e1fb744f6fa77b41ba869b2/src/bonsai/bonsai/bim/module/geometry/operator.py#L989)\n — `def track_aggregates(self, objects_to_remove)` stores live wrappers\n in a `set`\n- [operator.py L955](https://github.com/IfcOpenShell/IfcOpenShell/blob/1af5cc9bbe5e81814e1fb744f6fa77b41ba869b2/src/bonsai/bonsai/bim/module/geometry/operator.py#L955)\n — `self.delete_empty_aggregates(aggregates_to_check)` runs after the\n parts were removed\n- [operator.py L1009](https://github.com/IfcOpenShell/IfcOpenShell/blob/1af5cc9bbe5e81814e1fb744f6fa77b41ba869b2/src/bonsai/bonsai/bim/module/geometry/operator.py#L1009)\n — `aggregate.id()` on a wrapper whose C++ entity was already destroyed\n (the `try/except` at\n [L1008-1011](https://github.com/IfcOpenShell/IfcOpenShell/blob/1af5cc9bbe5e81814e1fb744f6fa77b41ba869b2/src/bonsai/bonsai/bim/module/geometry/operator.py#L1008)\n cannot catch a native segfault)\n\n**Reproduction**\n\nSelf-contained script (`repro_segfault.py.txt`, attached). Only Bonsai +\nifcopenshell, no third-party add-on: builds a fresh in-memory IFC4 model\nwith an `IfcStair` + parts, links Blender objects to the entities,\nselects the aggregate and all of its parts, and runs\n`bpy.ops.bim.override_object_delete(is_batch=False)`.\n\n```bash\nblender --background --python repro_segfault.py\n```\n\nExpected: Blender segfaults and writes `blender.crash.txt`. If the bug\nis fixed, the script prints `DELETE_FINISHED` and the IFC graph is\nempty.\n\n**Backtrace** (native + Python, from `blender.crash.txt` written by the\nscript reproduction):\n\n```\n/lib/x86_64-linux-gnu/libstdc++.so.6(__dynamic_cast+0x21)\n.../ifcopenshell/_ifcopenshell_wrapper.cpython-313-x86_64-linux-gnu.so(+0x36eb7b8)\n\n# Python backtrace\n File \".../ifcopenshell/ifcopenshell_wrapper.py\", line 6352 in id\n File \".../ifcopenshell/entity_instance.py\", line 442 in id\n File \".../bonsai/bim/module/geometry/operator.py\", line 1009 in delete_empty_aggregates\n File \".../bonsai/bim/module/geometry/operator.py\", line 955 in _execute\n File \".../bonsai/bim/ifc.py\", line 562 in execute_ifc_operator\n File \".../bonsai/bim/module/geometry/operator.py\", line 853 in execute\n```\n\nThe Python frame confirms the failure is exactly `aggregate.id()` at\n`operator.py:1009`, reached from `delete_empty_aggregates` after the\ndelete loop.\n\n**Expected behaviour**\n\nDeleting a selection that includes both an aggregate and all of its\nparts must complete without accessing IFC entity handles that were\ninvalidated earlier in the same operation.\n\n**Proposed direction**\n\nStore aggregate STEP ids before deletion rather than entity wrappers.\nAfter deletion, re-resolve each id from the active IFC file and ignore\nids that no longer resolve. This avoids dereferencing an entity wrapper\nafter its native object has been removed.\n\nBonsai already ships\n[`tool.Ifc.get_entity_by_id(entity_id)`](https://github.com/IfcOpenShell/IfcOpenShell/blob/1af5cc9bbe5e81814e1fb744f6fa77b41ba869b2/src/bonsai/bonsai/tool/ifc.py#L166),\nwhich wraps `file.by_id()` in `try/except RuntimeError` and returns\n`None` when the entity no longer exists — ideal for re-resolving ids\nsafely.\n\nThis is a pragmatic mitigation at the Bonsai layer. The underlying class\nof bug — Python wrappers left dangling after their C++ entity is removed\n— has precedents in ifcopenshell core, notably\n[#4564](https://github.com/IfcOpenShell/IfcOpenShell/issues/4564)\n(segfault when using an entity saved in a variable after it was removed;\nthe recommended workaround there was exactly \"don't keep the entity,\nre-fetch it when needed\") and\n[#1224](https://github.com/IfcOpenShell/IfcOpenShell/issues/1224)\n(\"removal with inverse attributes is still buggy\"), so a deeper fix in\ncore would also be welcome.\n\nThe fix described here is already implemented and working in the add-on\nthat hit this bug, as a temporary monkey-patch (id-based\n`track_aggregates` / `delete_empty_aggregates`). I'd be happy to port it\nto `operator.py` as a pull request with a regression test if that helps.\n\n**Verification performed**\n\n- Crash reproduced on factory Bonsai `0.8.6a260813` (pristine\n `OverrideDelete`, no add-on monkey-patching): Blender segfaults and\n writes `blender.crash.txt` with the backtrace above.\n- Not verified against the newest unstable build; the version tested is\n the latest distributed via the Blender 5.2 extension manager at the\n time of writing.\n\n### Attachments\n\n[repro_segfault.py.txt](https://github.com/user-attachments/files/31059821/repro_segfault.py.txt)\n[Example.ifc.txt](https://github.com/user-attachments/files/31059847/Example.ifc.txt)\n\n### Debug and Error Output\n\n```true\n\n```","author":{"url":"https://github.com/odofaro","@type":"Person","name":"odofaro"},"datePublished":"2026-08-14T07:55:54Z","url":"https://github.com/IfcOpenShell/IfcOpenShell/issues/9299"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:dc803c4d-ebae-93ed-9023-9e0b006eef1c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D080:13C02D:3BF57F:54D80A:6B046F8B |
| html-safe-nonce | 9f35fad85861181d908e561d0ced50d015a391e6d61292c3b61abfccf2117036 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMDgwOjEzQzAyRDozQkY1N0Y6NTREODBBOjZCMDQ2RjhCIiwidmlzaXRvcl9pZCI6IjIxNjY2NjY4NjM1MjQ5OTkwNTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 66d91b48df68d0fe1c8e52f7456499dc9f3b70d559228e326d5deb8019e4aa55 |
| hovercard-subject-tag | issue:5149565110 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/IfcOpenShell/IfcOpenShell/9299/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8631a3698735643b34f5092b23bd7bdc8d3c34faf4a81d8d0b3c18c153f96e6d/IfcOpenShell/IfcOpenShell/issues/9299 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8631a3698735643b34f5092b23bd7bdc8d3c34faf4a81d8d0b3c18c153f96e6d/IfcOpenShell/IfcOpenShell/issues/9299 |
| og:image:alt | Bug Description Environment os: Linux (Linux Mint 22.3, kernel 6.14.0-37-generic, glibc 2.39) os_version: #37~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC python_version: 3.13.13 architecture: x86_64 blender... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | odofaro |
| hostname | github.com |
| expected-hostname | github.com |
| None | ae8802492f12d3ba4f6b0d814054e617a2a5616b6327bf8555c10cd5b0dc2a6f |
| turbo-cache-control | no-preview |
| go-import | github.com/IfcOpenShell/IfcOpenShell git https://github.com/IfcOpenShell/IfcOpenShell.git |
| octolytics-dimension-user_id | 13692563 |
| octolytics-dimension-user_login | IfcOpenShell |
| octolytics-dimension-repository_id | 40473201 |
| octolytics-dimension-repository_nwo | IfcOpenShell/IfcOpenShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 40473201 |
| octolytics-dimension-repository_network_root_nwo | IfcOpenShell/IfcOpenShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cfb5f24c6e01d85f70804652a5107e5cac03a161 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width