Segfault when referencing a removed action via Python #39600

Closed
opened 2014-04-04 19:29:13 +02:00 by Jason van Gumster · 5 comments

System Information
Arch Linux, Nvidia Quadro K5000M

Blender Version
Broken: master - 2dedf2a

Short description of error
Blender crashes if you try to reference an action datablock after it's been removed via Python.

Exact steps for others to reproduce the error
Use the attached .blend file

  1. Open the file and run the embedded python script.
  2. Blender will crash if you click anywhere in the interface

Also attached is a gdb backtrace

action_ref-segfault.blend

action_ref-segfault_backtrace.txt

**System Information** Arch Linux, Nvidia Quadro K5000M **Blender Version** Broken: master - 2dedf2a **Short description of error** Blender crashes if you try to reference an action datablock after it's been removed via Python. **Exact steps for others to reproduce the error** Use the attached .blend file 1. Open the file and run the embedded python script. 2. Blender will crash if you click anywhere in the interface Also attached is a gdb backtrace [action_ref-segfault.blend](https://archive.blender.org/developer/F83952/action_ref-segfault.blend) [action_ref-segfault_backtrace.txt](https://archive.blender.org/developer/F83953/action_ref-segfault_backtrace.txt)
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'
Author
Member

Added subscriber: @JasonvanGumster

Added subscriber: @JasonvanGumster
Member

Added subscribers: @ideasman42, @LukasTonne

Added subscribers: @ideasman42, @LukasTonne
Member

Unfortunately there is no good way to support explicit deletion of ID data blocks from python ...

  • ID.user_clear simply sets the user count to 0 - without any kind of check. I'm not sure if there is a legit use case for this function, but it has to be used with extreme care and should be avoided whenever possible.
  • bpy.data.***.remove is even more dangerous, it directly deletes ID blocks from the library, but also doesn't clear any references to these blocks in the general case, leaving you with dangling pointers and invalid python objects (such as the action variable in your case)

According to @ideasman42 there is no proper way to support these things efficiently. There is a build option WITH_PYTHON_SAFETY which would at least keep python variables valid, but still doesn't solve issues with remove() function calls.

Some data blocks have "unlink" functionality build into their freeing functions (Object, Group, Text, ...) which should help keep the C pointer sane, but this is not universally implemented (in particular Action doesn't do it yet).

TL;DR: Never ever use bpy.data.xxx.remove() unless you're absolutely sure what you are doing (basically: be sure there are no references to that data block left). Sorry, it's a difficult technical issue :(

Unfortunately there is no good way to support explicit deletion of ID data blocks from python ... * `ID.user_clear` simply sets the user count to 0 - without any kind of check. I'm not sure if there is a legit use case for this function, but it has to be used with extreme care and should be avoided whenever possible. * `bpy.data.***.remove` is even more dangerous, it directly deletes ID blocks from the library, but also doesn't clear any references to these blocks in the general case, leaving you with dangling pointers and invalid python objects (such as the `action` variable in your case) According to @ideasman42 there is no proper way to support these things efficiently. There is a build option WITH_PYTHON_SAFETY which would at least keep python variables valid, but still doesn't solve issues with `remove()` function calls. *Some* data blocks have "unlink" functionality build into their freeing functions (Object, Group, Text, ...) which should help keep the C pointer sane, but this is not universally implemented (in particular Action doesn't do it yet). TL;DR: **Never ever** use bpy.data.xxx.remove() unless you're absolutely sure what you are doing (basically: be sure there are no references to that data block left). Sorry, it's a difficult technical issue :(
Member

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Lukas Tönne self-assigned this 2014-04-05 12:23:05 +02:00
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
2 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#39600
No description provided.