"Create pose asset" button hangs blender #91046

Closed
opened 2021-08-30 10:10:22 +02:00 by Roman · 20 comments

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 minimal-attempt.blend

Click "Create pose asset" in the sidebar of the action editor
pose-asset-bug.png
Result: blender hangs and never wakes up.

Originally attached file:
posebug.blend

**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 [minimal-attempt.blend](https://archive.blender.org/developer/F10382906/minimal-attempt.blend) Click "Create pose asset" in the sidebar of the action editor ![pose-asset-bug.png](https://archive.blender.org/developer/F10351779/pose-asset-bug.png) Result: blender hangs and never wakes up. Originally attached file: [posebug.blend](https://archive.blender.org/developer/F10351777/posebug.blend)
Author

Added subscriber: @rwman

Added subscriber: @rwman
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Member

Can confirm, will check.

Can confirm, will check.
Member

Added subscriber: @dr.sybren

Added subscriber: @dr.sybren
Member

Related to 6e01b52100, 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 @dr.sybren

Related to 6e01b52100, 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 @dr.sybren
Sybren A. Stüvel self-assigned this 2021-09-06 15:09:31 +02:00

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

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.

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.

@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.

@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.
Author

In #91046#1217235, @dr.sybren wrote:
@rwman you can work around this issue by rewriting your shapekey driver.

Thanks! Will try

> In #91046#1217235, @dr.sybren wrote: > @rwman you can work around this issue by rewriting your shapekey driver. Thanks! Will try

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'

This is resolved in fc46035117

This is resolved in fc46035117

This issue was referenced by f13eb69269

This issue was referenced by f13eb692692f9c622783a465e114c4e8c046782a

Added subscriber: @brecht

Added subscriber: @brecht

Changed status from 'Resolved' to: 'Confirmed'

Changed status from 'Resolved' to: 'Confirmed'

The fix for this was reverted, see fc46035117.

The fix for this was reverted, see fc46035117.

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.

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.

Added subscriber: @dfelinto

Added subscriber: @dfelinto

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'

This was properly fixed by fe4286435c, which includes the diff from @brecht. Thanks Brecht!

This was properly fixed by fe4286435c, which includes the diff from @brecht. Thanks Brecht!
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
6 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#91046
No description provided.