Use of deprectated PyEval_ReleaseLock() causes crash when Blender built against Python 3.9.0 #81688

Closed
opened 2020-10-13 21:27:42 +02:00 by Andrew J. Hesford · 14 comments

System Information
Operating system: Void Linux, x86_64, Python 3.9.0
Graphics card: Radeon RX 580

Blender Version
Broken: 2.83.6, 2.90.1, with Python 3.9.0
Worked: At least 2.83.6 with Python < 3.9.

Short description of error
In the file source/blender/python/generic/bpy_threads.c, the function BPY_thread_save calls PyThreadState_Swap and, if that function returns null, PyEval_ReleaseLock. The function PyEval_ReleaseLock has been deprecated since Python 3.2. In release versions of Python less than 3.9.0, this seems to be of no concern, but this call will cause a segfault with Python 3.9.0.

The same issue affects gdb when linked against Python 3.9.0; the Fedora project documents a fix the replaces both the call to PyThreadState_Swap and PyEval_ReleaseLock with a single call to PyEval_SaveThread. (The Fedora patch actually address two separate issues, one of which is related to acquiring the GIL at the right time. Only the first part of the patch comment and the corresponding last part of the patch seem relevant here.)

Exact steps for others to reproduce the error

  1. Compile Blender (apparently even the master branch, but certainly 2.83.6 or 2.90.1) against Python 3.9.0.
  2. Launch Blender.
  3. Create a new file ("General").
  4. Switch to Edit Mode.
  5. Switch to Face Select.
  6. Select a face on the default cube.
  7. Press "e" and attempt to extrude the face.

At this point, Blender crashes with a traceback that implicates PyEval_ReleaseLock.

Recommended Solution
I believe this issue is resolved (and have tested the fix with Blender 2.83.6 and 2.90.1, linked against Python 3.9.0, on Void Linux) by redefining BPY_thread_save in source/blender/python/generic/bpy_threads.c to just call PyEval_SaveThread:

BPy_ThreadStatePtr BPY_thread_save(void)
{
  PyThreadState *tstate = PyEval_SaveThread();
  return (BPy_ThreadStatePtr)tstate;
}

Note
I am not a Blender user, but am addressing a Reddit report about the issue.

**System Information** Operating system: Void Linux, x86_64, Python 3.9.0 Graphics card: Radeon RX 580 **Blender Version** Broken: 2.83.6, 2.90.1, with Python 3.9.0 Worked: At least 2.83.6 with Python < 3.9. **Short description of error** In the file `source/blender/python/generic/bpy_threads.c`, the function `BPY_thread_save` calls `PyThreadState_Swap` and, if that function returns null, `PyEval_ReleaseLock`. The function `PyEval_ReleaseLock` has been [deprecated since Python 3.2](https://docs.python.org/3/c-api/init.html#c.PyEval_ReleaseLock). In release versions of Python less than 3.9.0, this seems to be of no concern, but this call will cause a segfault with Python 3.9.0. The same issue affects gdb when linked against Python 3.9.0; the Fedora project [documents a fix](https://src.fedoraproject.org/rpms/gdb/blob/28b99d9981ec195cc7dfedc33f8ec859607af381/f/gdb-rhbz1829702-fix-python39.patch) the replaces *both* the call to `PyThreadState_Swap` and `PyEval_ReleaseLock` with a single call to `PyEval_SaveThread`. (The Fedora patch actually address two separate issues, one of which is related to acquiring the GIL at the right time. Only the first part of the patch comment and the corresponding *last* part of the patch seem relevant here.) **Exact steps for others to reproduce the error** 1. Compile Blender (apparently even the master branch, but certainly 2.83.6 or 2.90.1) against Python 3.9.0. 2. Launch Blender. 3. Create a new file ("General"). 4. Switch to Edit Mode. 5. Switch to Face Select. 6. Select a face on the default cube. 7. Press "e" and attempt to extrude the face. At this point, Blender crashes with a traceback that implicates `PyEval_ReleaseLock`. **Recommended Solution** I believe this issue is resolved (and have tested the fix with Blender 2.83.6 and 2.90.1, linked against Python 3.9.0, on Void Linux) by redefining `BPY_thread_save` in `source/blender/python/generic/bpy_threads.c` to just call `PyEval_SaveThread`: ``` BPy_ThreadStatePtr BPY_thread_save(void) { PyThreadState *tstate = PyEval_SaveThread(); return (BPy_ThreadStatePtr)tstate; } ``` **Note** I am not a Blender user, but am addressing a [Reddit report about the issue](https://www.reddit.com/r/voidlinux/comments/j9sj8x/blender_crashing_importing_obj/g8ppgdf).

Added subscriber: @ahesford

Added subscriber: @ahesford

#83772 was marked as duplicate of this issue

#83772 was marked as duplicate of this issue

#83093 was marked as duplicate of this issue

#83093 was marked as duplicate of this issue

blender/blender-addons#82829 was marked as duplicate of this issue

blender/blender-addons#82829 was marked as duplicate of this issue

#82275 was marked as duplicate of this issue

#82275 was marked as duplicate of this issue

#82471 was marked as duplicate of this issue

#82471 was marked as duplicate of this issue

This issue was referenced by c7236ef4f1

This issue was referenced by c7236ef4f1da68978dbd1e9777b904fef8103138

This issue was referenced by 5edba9b42f

This issue was referenced by 5edba9b42f684bf8b99894bb6988e7f46180e12c

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

Changed status from 'Needs Triage' to: 'Resolved'
Campbell Barton self-assigned this 2020-10-14 09:53:20 +02:00

Added subscribers: @madman123456, @rjg

Added subscribers: @madman123456, @rjg

Added subscribers: @cosimo-3, @EAW

Added subscribers: @cosimo-3, @EAW

Added subscriber: @ilbozo

Added subscriber: @ilbozo

Added subscriber: @thegeko

Added subscriber: @thegeko

Added subscriber: @hopr6868

Added subscriber: @hopr6868
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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 & 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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
Asset System
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
4 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#81688
No description provided.