Title: Polyline insertion near heavy linked IFC models: ray_cast_by_proximity_2d crash on None verts + severe slowdown from snapping against linked geometry · Issue #8187 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: Polyline insertion near heavy linked IFC models: ray_cast_by_proximity_2d crash on None verts + severe slowdown from snapping against linked geometry · Issue #8187 · IfcOpenShell/IfcOpenShell
X Title: Polyline insertion near heavy linked IFC models: ray_cast_by_proximity_2d crash on None verts + severe slowdown from snapping against linked geometry · Issue #8187 · IfcOpenShell/IfcOpenShell
Description: Bug Description Summary Inserting an IFC element via the polyline tool (Shift+A) in a scene containing a heavy linked IFC model has two distinct problems, both in the snap raycast path. Both have a confirmed fix below (tested on my proje...
Open Graph Description: Bug Description Summary Inserting an IFC element via the polyline tool (Shift+A) in a scene containing a heavy linked IFC model has two distinct problems, both in the snap raycast path. Both have a...
X Description: Bug Description Summary Inserting an IFC element via the polyline tool (Shift+A) in a scene containing a heavy linked IFC model has two distinct problems, both in the snap raycast path. Both have a...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/issues/8187
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Polyline insertion near heavy linked IFC models: ray_cast_by_proximity_2d crash on None verts + severe slowdown from snapping against linked geometry","articleBody":"### Bug Description\n\n**Summary**\nInserting an IFC element via the polyline tool (Shift+A) in a scene containing a heavy linked IFC model has two distinct problems, both in the snap raycast path. Both have a confirmed fix below (tested on my project — crash gone, insertion went from ~30s to instant).\n\nProblem 1 — Crash: TypeError: cannot unpack non-iterable NoneType\n\nIn Raycast.ray_cast_by_proximity_2d (bonsai/tool/raycast.py), edge vertices are projected to 2D via view3d_utils.location_3d_to_region_2d, which returns None for vertices behind the camera / outside the projection. The block that builds edge_verts only handles the case where exactly one vertex is None (the ^ XOR at ~line 396). When both vertices project to None — an entire edge behind the camera, common when the viewport is close to or inside dense linked geometry — it stores (None, None), and the following loop does p0x, p0y = p0 (line 424), unpacking None and raising the TypeError. The crash fires on every handle_mouse_move, making placement impossible.\n\nFix (guard the loop):\n###################################\npython \n\nfor e in edges:\n p0, p1 = edge_verts[e]\n if p0 is None or p1 is None:\n continue\n p0x, p0y = p0\n p1x, p1y = p1\n###################################\nThese edges aren't on screen, so no usable snap is lost. Also covers the case where intersect_edge_region_border returns None.\n\n\n\n**Problem 2 — Severe slowdown: snap evaluates heavy linked models**\n\nSnap.detect_snapping_points calls Raycast.filter_objects_to_raycast, which adds every bounding-box-hit object to the raycast list, including heavy linked reference models. On a federated project this makes each insertion take ~30s before the modal even responds. Excluding the linked collection from the View Layer avoids it, but also hides the model.\n\nSuggested fix — let filter_objects_to_raycast skip linked reference objects, ideally behind a user-facing toggle:\n###################################\npython \n\n@classmethod\n def _is_linked_reference(cls, obj):\n if getattr(obj, \"library\", None) is not None:\n return True\n if getattr(obj, \"override_library\", None) is not None:\n return True\n inst = getattr(obj, \"instance_collection\", None)\n if inst is not None and getattr(inst, \"library\", None) is not None:\n return True\n return False\n###################################\n\nand, inside the loop in filter_objects_to_raycast, before processing each object:\n###################################\npython \n\nfor obj, bbox_2d in objs_2d_bbox:\n if cls.SKIP_LINKED_OBJECTS_IN_SNAP and cls._is_linked_reference(obj):\n continue\n ...\n###################################\nThis keeps linked models visible while excluding them from snap evaluation, addressing both the performance cost and the crash source at once. A toggle (UI/keymap) lets users still snap onto linked geometry when needed.\n\n\n**To Reproduce**\nLoad a heavy linked IFC model (mine: ~3,863 objects, ~1.42M vertices, ~2.57M faces).\nShift+A to insert a new IFC element near the linked geometry.\nMove the mouse while the polyline modal is active → crash (Problem 1) and/or ~30s freeze before the modal responds (Problem 2).\n\n**Traceback (Problem 1)**\n###################################\nFile \"...\\bonsai\\bim\\module\\model\\polyline.py\", line 411, in handle_mouse_move\n detected_snaps = tool.Snap.detect_snapping_points(context, event, self.objs_2d_bbox, self.tool_state)\nFile \"...\\bonsai\\tool\\snap.py\", line 416, in detect_snapping_points\n snap_points = tool.Raycast.ray_cast_by_proximity_2d(context, event, snap_obj)\nFile \"...\\bonsai\\tool\\raycast.py\", line 424, in ray_cast_by_proximity_2d\n p0x, p0y = p0\n ^^^^^^^^\nTypeError: cannot unpack non-iterable NoneType object\n###################################\n\n**Validation**\nBoth fixes applied locally and tested: the crash no longer occurs, and with linked objects skipped in the snap filter, insertion near the linked model is instant (was ~30s) while the model stays visible.\n\n\n\n**Environment**\n\nOS: Windows\nBlender: 5.1.2 (portable)\nPython: 3.13\nBonsai: v0.8.5\n\n### Attachments\n\n_No response_\n\n### Debug and Error Output\n\n```true\n\n```","author":{"url":"https://github.com/valentenet","@type":"Person","name":"valentenet"},"datePublished":"2026-06-19T13:01:15Z","url":"https://github.com/IfcOpenShell/IfcOpenShell/issues/8187"}
| 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:a6849fcc-79f8-5a9c-151d-a9a2d3005de4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A01C:72378:36F7DE:493582:6B04B9FC |
| html-safe-nonce | 1f0c9e633431fa8532038591891bb3f015b1b9e12ae4622f641ae9796084e2ce |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDFDOjcyMzc4OjM2RjdERTo0OTM1ODI6NkIwNEI5RkMiLCJ2aXNpdG9yX2lkIjoiNTAwMDUwODM3NzcxNjk2NjM2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 5e9b09affd571690ac5e37fa141f709f815ccee1fdc43253b3c54308ce530fa4 |
| hovercard-subject-tag | issue:4700896062 |
| 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/8187/issue_layout |
| twitter:image | https://opengraph.githubassets.com/af7e64d60899cd2d34afb6578cd783a3a526adf4c2154bc51171395185cab20b/IfcOpenShell/IfcOpenShell/issues/8187 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/af7e64d60899cd2d34afb6578cd783a3a526adf4c2154bc51171395185cab20b/IfcOpenShell/IfcOpenShell/issues/8187 |
| og:image:alt | Bug Description Summary Inserting an IFC element via the polyline tool (Shift+A) in a scene containing a heavy linked IFC model has two distinct problems, both in the snap raycast path. Both have a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | valentenet |
| hostname | github.com |
| expected-hostname | github.com |
| None | 378bd702ac792b3550e484ad39d9a898fcd25bb52ba6962b0c9cc457c1ea71c7 |
| 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 | b032e77f1ea437ede6c115446a0a467709b468e7 |
| 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