René's URL Explorer Experiment


Title: Snap crash: TypeError 'cannot unpack non-iterable NoneType' in ray_cast_by_proximity_2d when edges fall behind the camera plane · Issue #9286 · IfcOpenShell/IfcOpenShell · GitHub

Open Graph Title: Snap crash: TypeError 'cannot unpack non-iterable NoneType' in ray_cast_by_proximity_2d when edges fall behind the camera plane · Issue #9286 · IfcOpenShell/IfcOpenShell

X Title: Snap crash: TypeError 'cannot unpack non-iterable NoneType' in ray_cast_by_proximity_2d when edges fall behind the camera plane · Issue #9286 · IfcOpenShell/IfcOpenShell

Description: Bug Description Placing a window (or any product placed with the polyline/draw-occurrence tool) intermittently fails with: File "bonsai\tool\raycast.py", line 442, in ray_cast_by_proximity_2d p0x, p0y = p0 TypeError: cannot unpack non-it...

Open Graph Description: Bug Description Placing a window (or any product placed with the polyline/draw-occurrence tool) intermittently fails with: File "bonsai\tool\raycast.py", line 442, in ray_cast_by_proximity_2d p0x, ...

X Description: Bug Description Placing a window (or any product placed with the polyline/draw-occurrence tool) intermittently fails with: File "bonsai\tool\raycast.py", line 442, in ray_cast_by_proximit...

Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/issues/9286

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.112.3


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Snap crash: TypeError 'cannot unpack non-iterable NoneType' in ray_cast_by_proximity_2d when edges fall behind the camera plane","articleBody":"### Bug Description\n\nPlacing a window (or any product placed with the polyline/draw-occurrence tool) intermittently fails with:\n\n```\nFile \"bonsai\\tool\\raycast.py\", line 442, in ray_cast_by_proximity_2d\n    p0x, p0y = p0\nTypeError: cannot unpack non-iterable NoneType object\n```\n\nIt is not tied to a particular IFC file — it depends on where the camera sits, which is why it only happens sometimes. It occurs in a normal perspective 3D view (not camera view).\n\n**To reproduce**\n\n1. Open a model containing wireframe snap objects (meshes with no faces, curves — grid axes, annotations, axis lines).\n2. Put the viewport in perspective and move the camera so that it sits *right next to / inside* such an object, i.e. part of the object is behind the camera plane.\n3. Start `Add Occurrence` (e.g. a window) and move the mouse over the wall.\n4. The modal operator aborts with the traceback above.\n\nFull traceback:\n\n```\nFile \"bonsai\\bim\\module\\model\\workspace.py\", line 1192, in hotkey_S_A\n    return bpy.ops.bim.draw_occurrence(\"INVOKE_DEFAULT\")\nFile \"bonsai\\bim\\module\\model\\polyline.py\", line 470, in invoke\n    detected_snaps = tool.Snap.detect_snapping_points(context, event, self.objs_2d_bbox, self.tool_state)\nFile \"bonsai\\tool\\snap.py\", line 394, in detect_snapping_points\n    closest_snaps = tool.Raycast.ray_cast_and_get_closest_to_camera_snaps(context, event, objs_to_raycast)\nFile \"bonsai\\tool\\raycast.py\", line 884, in ray_cast_and_get_closest_to_camera_snaps\n    hit_obj, hit = cls.process_wireframe_snap_obj(context, event, snap_obj, ray_origin, closest_snaps)\nFile \"bonsai\\tool\\raycast.py\", line 829, in process_wireframe_snap_obj\n    snap_points = tool.Raycast.ray_cast_by_proximity_2d(context, event, snap_obj)\nFile \"bonsai\\tool\\raycast.py\", line 442, in ray_cast_by_proximity_2d\n    p0x, p0y = p0\nTypeError: cannot unpack non-iterable NoneType object\n```\n\n### Root cause\n\n`Raycast.ray_cast_by_proximity_2d` builds `edge_verts[e] = (p0, p1)` with the 2D screen positions of every edge returned by the BVH, then unpacks them unconditionally at line 442. `view3d_utils.location_3d_to_region_2d` returns `None` for any point behind the camera plane, and **two** paths store a `None` in that map:\n\nhttps://github.com/IfcOpenShell/IfcOpenShell/blob/v0.8.0/src/bonsai/bonsai/tool/raycast.py#L401-L415\n\n1. **Both endpoints behind the camera plane.** `(v1_2d is None) ^ (v2_2d is None)` is `False`, so the `else` branch stores `(None, None)`.\n2. **One endpoint behind the camera plane, the other in front of it but nearer than `clip_start`.** The xor branch is taken, but the segment never crosses the near plane, so `intersect_edge_region_border()` returns `None` (printing *\"No intersection with viewport near plane found for the segment.\"* to the console) and `(None, v2_2d)` is stored.\n\nEither way line 442 unpacks `None`.\n\nWhy an edge that is behind the camera reaches this code at all: the BVH boxes are axis-aligned in **world** space, while the camera plane generally is not. A leaf box can therefore straddle the camera plane, be hit by the mouse ray (`t >= 0`), and hand over edges that lie entirely behind the viewer. This is what makes the crash camera-position dependent, hence intermittent.\n\nNote that the other caller of the same helper already guards against the `None` return:\n\nhttps://github.com/IfcOpenShell/IfcOpenShell/blob/v0.8.0/src/bonsai/bonsai/tool/raycast.py#L114-L120\n\nThis call site never did. The bug predates the recent BVH/2D-projection optimisations — those did not touch this logic.\n\n### Reproduction (headless)\n\nI reproduced it outside the UI with a fake viewport (perspective, camera looking along the world `+X+Y` diagonal so the camera plane is not world-aligned) and a 4-vertex / 2-edge wireframe object with one edge sitting just behind the camera plane, calling `ray_cast_by_proximity_2d` directly. Against pristine `v0.8.0`:\n\n```\n=== CASE_A_both_endpoints_behind ===\n  edge 1 endpoints behind camera plane: True, True\n  BVH leaf boxes hit by the ray: 63, edges collected: [0, 1]\n  raycast.py:442 TypeError: cannot unpack non-iterable NoneType object\n\n=== CASE_B_near_plane_not_crossed ===\n  edge 1 endpoints behind camera plane: True, False\n  No intersection with viewport near plane found for the segment.\n  raycast.py:442 TypeError: cannot unpack non-iterable NoneType object\n\n2 of 2 cases crashed\n```\n\n### Suggested fix\n\nSkip edges with no usable on-screen projection, and iterate `edge_verts` instead of `edges` (some edges are now absent from it). This matches what the vertex loop just above already does — a vertex that does not project is skipped — and an edge that is not on screen has no 2D proximity snap to offer anyway.\n\n```diff\n             v1_2d = verts_2d.get(verts_idx[0])\n             v2_2d = verts_2d.get(verts_idx[1])\n+            if v1_2d is None and v2_2d is None:\n+                # Edge is entirely behind the camera plane, there is nothing on screen to snap to.\n+                continue\n             if (v1_2d is None) ^ (v2_2d is None):\n                 point, _ = cls.intersect_edge_region_border(region, context.space_data, rv3d, v1, v2)\n+                if point is None:\n+                    # No point of the edge could be mapped to the region border.\n+                    continue\n                 if v1_2d is None:\n                     edge_verts[e] = (point, v2_2d)\n                 else:\n@@\n         count = 0\n         selected_edges = {}\n-        for e in edges:\n-            p0, p1 = edge_verts[e]\n+        for e, (p0, p1) in edge_verts.items():\n             p0x, p0y = p0\n```\n\nWith this applied, both cases above return snap points normally instead of crashing (`0 of 2 cases crashed`). I can open a PR if the approach looks right.\n\n### Unrelated latent bug spotted nearby\n\n`intersect_edge_region_border` picks the on-screen endpoint with a truthiness test:\n\nhttps://github.com/IfcOpenShell/IfcOpenShell/blob/v0.8.0/src/bonsai/bonsai/tool/raycast.py#L190\n\nA vertex projecting exactly to `(0, 0)` gives a falsy `Vector`, so the wrong endpoint is chosen. Should be `is not None`. Not the cause of this crash — mentioning it for completeness.\n\n### Debug and Error Output\n\nBonsai 0.8.6-alpha260720 (source at v0.8.0, 8dc1ee55b)\nBlender 5.1.0\nWindows 11, Python 3.13\n","author":{"url":"https://github.com/carlopav","@type":"Person","name":"carlopav"},"datePublished":"2026-08-11T19:05:17Z","url":"https://github.com/IfcOpenShell/IfcOpenShell/issues/9286"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:09d95008-609a-67a9-1c58-751604d274b7
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idEC98:64377:1C74CD:261403:6B04B402
html-safe-nonce5fffe67ee70c4fc2fe02373974729c37c9cc3ad89b71bd4c881cd27c616ca23f
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzk4OjY0Mzc3OjFDNzRDRDoyNjE0MDM6NkIwNEI0MDIiLCJ2aXNpdG9yX2lkIjoiMjI2ODc2NDgwNzQ1MDg5OTQ1OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac5b5e470b112a96ede62edc88f6d04d8a42bf1ee5576fc1adc94a2c8dcbe844d1
hovercard-subject-tagissue:5123643306
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/IfcOpenShell/IfcOpenShell/9286/issue_layout
twitter:imagehttps://opengraph.githubassets.com/926e083ec4fec96a7bf15941f6a2420420b2c056390391dd56851af04fb10a31/IfcOpenShell/IfcOpenShell/issues/9286
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/926e083ec4fec96a7bf15941f6a2420420b2c056390391dd56851af04fb10a31/IfcOpenShell/IfcOpenShell/issues/9286
og:image:altBug Description Placing a window (or any product placed with the polyline/draw-occurrence tool) intermittently fails with: File "bonsai\tool\raycast.py", line 442, in ray_cast_by_proximity_2d p0x, ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamecarlopav
hostnamegithub.com
expected-hostnamegithub.com
None378bd702ac792b3550e484ad39d9a898fcd25bb52ba6962b0c9cc457c1ea71c7
turbo-cache-controlno-preview
go-importgithub.com/IfcOpenShell/IfcOpenShell git https://github.com/IfcOpenShell/IfcOpenShell.git
octolytics-dimension-user_id13692563
octolytics-dimension-user_loginIfcOpenShell
octolytics-dimension-repository_id40473201
octolytics-dimension-repository_nwoIfcOpenShell/IfcOpenShell
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id40473201
octolytics-dimension-repository_network_root_nwoIfcOpenShell/IfcOpenShell
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releaseb032e77f1ea437ede6c115446a0a467709b468e7
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/IfcOpenShell/IfcOpenShell/issues/9286#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FIfcOpenShell%2FIfcOpenShell%2Fissues%2F9286
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FIfcOpenShell%2FIfcOpenShell%2Fissues%2F9286
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=IfcOpenShell%2FIfcOpenShell
Reloadhttps://github.com/IfcOpenShell/IfcOpenShell/issues/9286
Reloadhttps://github.com/IfcOpenShell/IfcOpenShell/issues/9286
Reloadhttps://github.com/IfcOpenShell/IfcOpenShell/issues/9286
IfcOpenShellhttps://github.com/IfcOpenShell
IfcOpenShellhttps://github.com/IfcOpenShell/IfcOpenShell
Codehttps://github.com/IfcOpenShell/IfcOpenShell
Issues1.2k (1.2k)https://github.com/IfcOpenShell/IfcOpenShell/issues
Pull requests941 (941)https://github.com/IfcOpenShell/IfcOpenShell/pulls
Discussionshttps://github.com/IfcOpenShell/IfcOpenShell/discussions
Actionshttps://github.com/IfcOpenShell/IfcOpenShell/actions
Projectshttps://github.com/IfcOpenShell/IfcOpenShell/projects
Wikihttps://github.com/IfcOpenShell/IfcOpenShell/wiki
Security and qualityhttps://github.com/IfcOpenShell/IfcOpenShell/security
Insightshttps://github.com/IfcOpenShell/IfcOpenShell/insights
https://github.com/IfcOpenShell/IfcOpenShell
New issuehttps://github.com/login?return_to=https://github.com/IfcOpenShell/IfcOpenShell/issues/9286
New issuehttps://github.com/login?return_to=https://github.com/IfcOpenShell/IfcOpenShell/issues/9286
Snap crash: TypeError 'cannot unpack non-iterable NoneType' in ray_cast_by_proximity_2d when edges fall behind the camera planehttps://github.com/IfcOpenShell/IfcOpenShell/issues/9286#top
https://github.com/carlopav
carlopavhttps://github.com/carlopav
on Aug 11, 2026https://github.com/IfcOpenShell/IfcOpenShell/issues/9286#issue-5123643306
https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.8.0/src/bonsai/bonsai/tool/raycast.py#L401-L415https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.8.0/src/bonsai/bonsai/tool/raycast.py#L401-L415
https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.8.0/src/bonsai/bonsai/tool/raycast.py#L114-L120https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.8.0/src/bonsai/bonsai/tool/raycast.py#L114-L120
https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.8.0/src/bonsai/bonsai/tool/raycast.py#L190https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.8.0/src/bonsai/bonsai/tool/raycast.py#L190
8dc1ee5https://github.com/IfcOpenShell/IfcOpenShell/commit/8dc1ee55b58f3952b7fb1ac43eccdc9df59d4c2b
https://github.com/carlopav
carlopavhttps://github.com/carlopav
on Aug 11, 2026https://github.com/IfcOpenShell/IfcOpenShell/issues/9286#issuecomment-5259304046
8dc1ee5https://github.com/IfcOpenShell/IfcOpenShell/commit/8dc1ee55b58f3952b7fb1ac43eccdc9df59d4c2b
brunoperdigaohttps://github.com/brunoperdigao
completedhttps://github.com/IfcOpenShell/IfcOpenShell/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Oct 3, 2026https://github.com/IfcOpenShell/IfcOpenShell/issues/9286#event-32376552828
https://github.com/brunoperdigao
brunoperdigaohttps://github.com/brunoperdigao
on Oct 3, 2026https://github.com/IfcOpenShell/IfcOpenShell/issues/9286#issuecomment-5964154103
#9337https://github.com/IfcOpenShell/IfcOpenShell/pull/9337
Sign up for freehttps://github.com/signup?return_to=https://github.com/IfcOpenShell/IfcOpenShell/issues/9286
Sign in to commenthttps://github.com/login?return_to=https://github.com/IfcOpenShell/IfcOpenShell/issues/9286
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.