Title: Bonsai: type thumbnail generation crashes Blender by starting threaded preview jobs during authoring · Issue #10138 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: Bonsai: type thumbnail generation crashes Blender by starting threaded preview jobs during authoring · Issue #10138 · IfcOpenShell/IfcOpenShell
X Title: Bonsai: type thumbnail generation crashes Blender by starting threaded preview jobs during authoring · Issue #10138 · IfcOpenShell/IfcOpenShell
Description: Bug Description bim.load_type_thumbnails calls Object.asset_generate_preview() once per type on the current Type Manager page. That function queues a threaded icon render job, and the job calls DEG_graph_build_from_view_layer() on a work...
Open Graph Description: Bug Description bim.load_type_thumbnails calls Object.asset_generate_preview() once per type on the current Type Manager page. That function queues a threaded icon render job, and the job calls DEG...
X Description: Bug Description bim.load_type_thumbnails calls Object.asset_generate_preview() once per type on the current Type Manager page. That function queues a threaded icon render job, and the job calls DEG...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/issues/10138
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bonsai: type thumbnail generation crashes Blender by starting threaded preview jobs during authoring","articleBody":"## Bug Description\n\n`bim.load_type_thumbnails` calls `Object.asset_generate_preview()` once per type on the\ncurrent Type Manager page. That function queues a **threaded** icon render job, and the job\ncalls `DEG_graph_build_from_view_layer()` on a worker thread. While those jobs are in flight,\nany authoring on the main thread can free or rebuild the objects, meshes and materials they are\nwalking, and Blender segfaults.\n\nBecause `bim.load_type_thumbnails` is also fired from property update callbacks\n(`update_ifc_class`, `update_type_page`, `update_search_name`) and thumbnails are invalidated\nby `mark_thumbnail_for_update` after parametric edits, this happens repeatedly during ordinary\nmodelling rather than only when the Type Manager is opened.\n\nI have hit this three times on two different projects and two different Blender versions. All\nthree crash reports show `bim.load_type_thumbnails()` in the operator log shortly beforehand.\n\n**Crash 1 — Blender 5.2.1**, in the outliner, reading a null `Collection` while rebuilding the\nview layer tree:\n\n```\nTreeDisplayViewLayer::add_layer_collections_recursive \u003c- read at 0x10\nTreeDisplayViewLayer::add_view_layer / build_tree\noutliner_build_tree -> draw_outliner -> ED_region_do_draw -> wm_draw_update\n```\n\n**Crash 2 — Blender 5.2.1**, in `context.selected_objects` from a viewport draw handler,\nreading a garbage `Base`:\n\n```\nBKE_base_is_visible \u003c- read at 0x26\nscreen_ctx_selected_objects -> ed_screen_context -> CTX_data_get\npyrna_struct_getattro -> ... -> cb_region_draw -> view3d_main_region_draw\n```\n\n**Crash 3 — Blender 5.1.2**, the decisive one: inside the preview job itself, on the job\nthread:\n\n```\nDepsgraphNodeBuilder::build_materials \u003c- read at 0x0\nDepsgraphNodeBuilder::build_object / build_view_layer\nDEG_graph_build_from_view_layer\nobject_preview_render\nicon_preview_startjob_all_sizes\ndo_job_thread\n```\n\nOperator log immediately before crash 3:\n\n```\nbpy.ops.bim.reassign_class() # rebuilds the object\nbpy.ops.bim.load_type_thumbnails() # queues N threaded preview jobs\nbpy.ops.bim.load_type_thumbnails()\nbpy.ops.bim.hotkey(hotkey=\"S_A\")\nbpy.ops.bim.create_instance() # creates objects, meshes, materials\nbpy.ops.bim.add_occurrence()\n\u003ccrash on the job thread>\n```\n\nCrashes 1 and 2 are consistent with the same race — `BKE_layer_collection_sync` rebuilds both\n`layer_collections` and `object_bases`, and each crash is a main-thread consumer walking one of\nthose halves — but only crash 3 proves the job can die on its own.\n\n### Why `asset_generate_preview()` is the threaded one\n\nOn blender/blender#105325, Philipp Oeser diagnosed it (comment 893982): \"this is indeed\ncaused by the fact that `ED_asset_generate_preview` calls `UI_icon_render_id` as a job, whereas\n`previews_id_ensure` doesnt\". The reporter there also found that `preview_ensure()` in a loop\ndid not crash where `asset_generate_preview()` did. Bonsai already calls `obj.preview_ensure()` immediately before, but that only allocates\nthe preview; `asset_generate_preview()` queues the render that actually draws thumbnails for\nobjects with mesh data, so it cannot simply be deleted without losing those thumbnails.\n\n### To reproduce\n\nNot reliably reproducible on demand — it is a race, and it took three occurrences over six\nweeks of normal use. It needs a project with enough element types that a Type Manager page\nholds several mesh-backed types, then: edit a type's geometry (invalidating its thumbnail),\nchange selection so a property callback re-fires `bim.load_type_thumbnails`, and immediately\nkeep authoring (`reassign_class`, `create_instance`, `add_occurrence`).\n\n### Suggested fix\n\nDo not start these jobs while the scene is being mutated. Since Python cannot cancel an\nin-flight preview job, the achievable approach is to queue the renders and start them one at a\ntime once the scene has settled — tracked with a `depsgraph_update_post` timestamp and a\n`bpy.app.timers` drain. This removes the \"N jobs in flight while authoring\" condition that all\nthree crashes share. It narrows the window rather than closing it completely; closing it needs\nthe upstream fix.\n\nI have a patch doing exactly that and will open a PR.\n\n## Attachments\n\nFull crash reports for all three available on request.\n\n## Debug and Error Output\n\n- Bonsai: 0.8.6a / 0.9.0a (both affected; the call is identical in each)\n- Blender: 5.1.2 (`ec6e62d40fa9`) and 5.2.1 (`9e2066aef7ef`)\n- OS: Windows 10\n- Relevant code: `tool/model.py` `Model.update_thumbnail_for_element`, and\n `bim/module/model/product.py` `LoadTypeThumbnails.execute`\n- Related: #6839 (thumbnails don't render — the fix that introduced the current\n `preview_ensure()` + `asset_generate_preview()` pairing, `c333535ae5`),\n blender/blender#105325, blender/blender#140903\n- Upstream report for the underlying threaded-depsgraph race, now filed:\n https://projects.blender.org/blender/blender/issues/166210\n\n","author":{"url":"https://github.com/theoryshaw","@type":"Person","name":"theoryshaw"},"datePublished":"2026-11-05T23:44:04Z","url":"https://github.com/IfcOpenShell/IfcOpenShell/issues/10138"}
| 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:b2a13a02-8f72-e248-0b16-2b04daab72ee |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BB84:3D1C6E:C19EA:112362:6B04638E |
| html-safe-nonce | 1de250ab21bf5a72caee5d7fd3b6b85a8e037df965731f2a1a9cb11499a63c05 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQjg0OjNEMUM2RTpDMTlFQToxMTIzNjI6NkIwNDYzOEUiLCJ2aXNpdG9yX2lkIjoiNzkzODc2NTg1MzIwMDUwNzc5MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 680c7d3b8106af892d9e871a3f0efc0d3155ef08be255846c26eb25da4fa1ff0 |
| hovercard-subject-tag | issue:6233713123 |
| 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/10138/issue_layout |
| twitter:image | https://opengraph.githubassets.com/83aed4429e093cca160b591c8118f47a9d38b3e14284463bd3ea8de6481b5b41/IfcOpenShell/IfcOpenShell/issues/10138 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/83aed4429e093cca160b591c8118f47a9d38b3e14284463bd3ea8de6481b5b41/IfcOpenShell/IfcOpenShell/issues/10138 |
| og:image:alt | Bug Description bim.load_type_thumbnails calls Object.asset_generate_preview() once per type on the current Type Manager page. That function queues a threaded icon render job, and the job calls DEG... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | theoryshaw |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2d58451b4bcb73c33c67bfb6b28fb75fe6d5e279daf9b560fa4fd832f3d8c9a6 |
| 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 | 03e114520787ad27289207f153520ef97461127c |
| 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