Page MenuHome

"Create pose asset" button hangs blender
Closed, ResolvedPublic

Description

System Information
Operating system: linux
Graphics card: amd

Blender Version
Broken: blender-3.0.0-alpha+master.4256eeeec4ca-linux.x86_64-release

Short description of error
Clicking "Create pose asset" button in the action editor hangs blender.

Exact steps for others to reproduce the error
Open attached blend file

Click "Create pose asset" in the sidebar of the action editor


Result: blender hangs and never wakes up.

Originally attached file:

Event Timeline

Philipp Oeser (lichtwerk) changed the task status from Needs Triage to Confirmed.Aug 30 2021, 10:56 AM

Can confirm, will check.

Related to rB6e01b52100f3: Assets: temporarily apply pose when generating preview image, hangs here:

1   tbb::internal::custom_scheduler<tbb::internal::IntelSchedulerTraits>::receive_or_steal_task(long&, long)                                   0x3cf185a  
2   tbb::internal::custom_scheduler<tbb::internal::IntelSchedulerTraits>::local_wait_for_all(tbb::task&, tbb::task *)                          0x3cf2ad7  
3   tbb::task::wait_for_all                                                                                           task.h              820  0x42b7977  
4   tbb::internal::task_group_base::wait                                                                              task_group.h        168  0x42b7de4  
5   tbb_task_pool_work_and_wait                                                                                       task_pool.cc        251  0x10aca404 
6   BLI_task_pool_work_and_wait                                                                                       task_pool.cc        500  0x10acaa2a 
7   blender::deg::deg_evaluate_on_refresh                                                                             deg_eval.cc         400  0x4031145  
8   deg_flush_updates_and_refresh                                                                                     depsgraph_eval.cc   58   0x4003baf  
9   DEG_evaluate_on_refresh                                                                                           depsgraph_eval.cc   75   0x4003c66  
10  action_preview_render_prepare                                                                                     render_preview.c    950  0x6099cc3  
11  action_preview_render                                                                                             render_preview.c    981  0x6099f19  
12  icon_preview_startjob_all_sizes                                                                                   render_preview.c    1680 0x609ba14  
13  ED_preview_icon_render                                                                                            render_preview.c    1788 0x609bda6  
14  icon_set_image                                                                                                    interface_icons.c   1426 0x4db87c6  
15  ui_id_preview_image_render_size                                                                                   interface_icons.c   1945 0x4db9d7d  
16  UI_icon_render_id                                                                                                 interface_icons.c   1963 0x4db9e03  
17  ED_asset_mark_id                                                                                                  asset_mark_clear.cc 56   0x49f67ba  
18  rna_ID_asset_mark                                                                                                 rna_ID.c            674  0x45c0358  
19  ID_asset_mark_call                                                                                                rna_ID_gen.c        1347 0x45c42eb

CC @Sybren A. Stüvel (sybren)

Philipp Oeser (lichtwerk) triaged this task as High priority.Aug 30 2021, 11:18 AM

This seems to be a threading issue, indeed. Running blender -t 1 doesn't hang.

The problem lies with the evaluation of drivers that require evaluation in Python. This tries to lock the GIL, causing deadlock. This helped me create a minimal example (just a single bone, with one driver, referencing one other object). I'll attach it to the description.

@Roman (rwman) you can work around this issue by rewriting your shapekey driver. Currently it has the expression 1-((var-0.02)*2.5)**2. Because of the square, this cannot be evaluated by Blender's simple expression evaluator, and thus uses Python to evaluate the expression. This is what is currently hanging (and is a bug that should be fixed). Changing it to 1-((var-0.02)*2.5)*((var-0.02)*2.5) makes it actually compatible with the simple expression evaluator, avoid Python, and be faster and not hang. You can also rewrite it to 1 - 6.25 * (var - 0.02) * (var - 0.02) and make it a little bit faster.

@Roman (rwman) you can work around this issue by rewriting your shapekey driver.

Thanks! Will try

The original commit + this additional change seems to fix both this bug and the render crash.

_PyThreadState_UncheckedGet() doesn't check if the current thread is actually holding the GIL.

diff --git a/source/blender/python/generic/bpy_threads.c b/source/blender/python/generic/bpy_threads.c
index 57eb3a8..54548b8 100644
--- a/source/blender/python/generic/bpy_threads.c
+++ b/source/blender/python/generic/bpy_threads.c
@@ -29,10 +29,9 @@
 /* analogue of PyEval_SaveThread() */
 BPy_ThreadStatePtr BPY_thread_save(void)
 {
-  /* Use `_PyThreadState_UncheckedGet()`, instead of more canonical `PyGILState_Check()` or
-   * `PyThreadState_Get()`, to avoid a fatal error issued when a thread state is NULL (the thread
-   * state can be NULL when quitting Blender). */
-  if (_PyThreadState_UncheckedGet()) {
+  /* Don't use `PyThreadState_Get()`, to avoid a fatal error issued when a thread state is NULL
+   * (the thread state can be NULL when quitting Blender). */
+  if (PyGILState_Check()) {
     return (BPy_ThreadStatePtr)PyEval_SaveThread();
   }
   return NULL;

Feel free to commit.

This was properly fixed by rBfe4286435c54, which includes the diff from @Brecht Van Lommel (brecht). Thanks Brecht!