Operator (e.g bpy.ops.object.data_transfer()) crashes when using context.copy() via addon #112299

Closed
opened 2023-09-12 21:11:33 +02:00 by Nick Alberelli · 7 comments

System Information
Operating system: Windows-10-10.0.19045-SP0 64 Bits
Graphics card: NVIDIA GeForce RTX 3070 Laptop GPU/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 536.99

Blender Version
Broken: version: 4.0.0 Alpha, branch: main, commit date: 2023-09-12 16:48, hash: b7ba7663a75d
Worked: version: 3.6.2, branch: blender-v3.6-release, commit date: 2023-08-16 16:43, hash: e53e55951e7a

This was caused by 6ba0346797

Short description of error
When using the operator bpy.ops.object.data_transfer() with a context override as defined in Blender Docs Blender will crash when invoking this from an add-on but doesn't crash if a similar script is executed in the text editor.

I discoverd this while working on a new add-on for the Blender Studio Pipeline.

Exact steps for others to reproduce the error

  1. Open Vertex_Group_Transfer.blend
  2. Install Add-on Vertex_Transfer_Addon.py
  3. Run script from text editor to see expected results
  4. In the 3D Viewport N-Panel find the Test Vertex Transfer Operator
  5. Ensure 'Camera' Object is the only active/selected object
  6. Assign Object with the name 'Source' as source obj
  7. Assign Object with the name 'Target' as target obj
  8. Run Operator and Blender will Crash

I have also attached a Crash Log from a debug build below.

**System Information** Operating system: Windows-10-10.0.19045-SP0 64 Bits Graphics card: NVIDIA GeForce RTX 3070 Laptop GPU/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 536.99 **Blender Version** Broken: version: 4.0.0 Alpha, branch: main, commit date: 2023-09-12 16:48, hash: `b7ba7663a75d` Worked: version: 3.6.2, branch: blender-v3.6-release, commit date: 2023-08-16 16:43, hash: `e53e55951e7a` This was caused by 6ba0346797 **Short description of error** When using the operator `bpy.ops.object.data_transfer()` with a context override as defined in [Blender Docs](https://docs.blender.org/api/current/bpy.ops.html#overriding-context) Blender will crash when invoking this from an add-on but doesn't crash if a similar script is executed in the text editor. I discoverd this while working on a new add-on for the Blender Studio Pipeline. <video src="/attachments/e4d9bf77-39a8-4885-8de0-288af763cbe5" title="DEMO_Vertex_Transfer_Crash.mp4" controls></video> **Exact steps for others to reproduce the error** 1. Open [Vertex_Group_Transfer.blend](/attachments/e554e60c-27dc-492f-9171-58ca6dcb2a11) 2. Install Add-on [Vertex_Transfer_Addon.py](/attachments/09cf3ac7-9d05-4ea9-9a2d-558808501e39) 3. Run script from text editor to see expected results 4. In the 3D Viewport N-Panel find the `Test Vertex Transfer` Operator 5. Ensure 'Camera' Object is the only active/selected object 6. Assign Object with the name 'Source' as source obj 7. Assign Object with the name 'Target' as target obj 8. Run Operator and Blender will Crash I have also attached a Crash Log from a debug build below.
Nick Alberelli added the
Priority
Normal
Type
Report
Status
Needs Triage
labels 2023-09-12 21:11:33 +02:00
Member

Can confirm. Crashed in ui_context_button_active. Will check how exactly it's triggering...

Can confirm. Crashed in `ui_context_button_active`. Will check how exactly it's triggering...
YimingWu added
Module
Python API
Status
Confirmed
Interest
User Interface
and removed
Status
Needs Triage
labels 2023-09-13 04:53:10 +02:00
Member

Looks like context.copy() somehow messed up the region argument into something invalid to be passed into ui_context_button_active, that's what causing you the crash. It can be that the region = data->menu->region; being invalid in ui_context_button_active. @JulianEisel or maybe @ideasman42 could you guys take a look at this function?

You don't need to copy context in the new override mechanism. Just assign what you want to override, and leave anything else as is, it will be copied from current context, so this works:

        override = {} #context.copy()
        override["selected_editable_objects"] = [target_obj, source_obj]
        override["active_object"] = source_obj
        override["object"] = source_obj  # Appears to be required in this context
        with context.temp_override(**override):
            bpy.ops.object.data_transfer(
                data_type="VGROUP_WEIGHTS",
                use_create=True,
                vert_mapping='POLYINTERP_NEAREST',
                layers_select_src="ACTIVE",
                layers_select_dst="NAME",
                mix_mode="REPLACE",
            )
~~Looks like context.copy() somehow messed up the `region` argument into something invalid to be passed into `ui_context_button_active`, that's what causing you the crash.~~ It can be that the `region = data->menu->region;` being invalid in `ui_context_button_active`. @JulianEisel or maybe @ideasman42 could you guys take a look at this function? You don't need to copy context in the new override mechanism. Just assign what you want to override, and leave anything else as is, it will be copied from current context, so this works: ``` override = {} #context.copy() override["selected_editable_objects"] = [target_obj, source_obj] override["active_object"] = source_obj override["object"] = source_obj # Appears to be required in this context with context.temp_override(**override): bpy.ops.object.data_transfer( data_type="VGROUP_WEIGHTS", use_create=True, vert_mapping='POLYINTERP_NEAREST', layers_select_src="ACTIVE", layers_select_dst="NAME", mix_mode="REPLACE", ) ```
Member

We still have context.copy() in the example here https://docs.blender.org/api/4.0/bpy.ops.html

Will raise prio here since it is a recent regression.

We still have `context.copy()` in the example here https://docs.blender.org/api/4.0/bpy.ops.html Will raise prio here since it is a recent regression.
Philipp Oeser added
Priority
High
and removed
Priority
Normal
labels 2023-09-13 09:46:40 +02:00
Member

This was caused by 6ba0346797

@joshm-2
@brecht

#109858 might be related

This was caused by 6ba0346797f43cd73eb1003ce65a62b8409203fb @joshm-2 @brecht #109858 might be related
Philipp Oeser changed title from `bpy.ops.object.data_transfer()` crashes when using `context.copy()` via addon to Operator (e.g `bpy.ops.object.data_transfer()`) crashes when using `context.copy()` via addon 2023-09-13 10:25:55 +02:00
Contributor

Investigating now.

Investigating now.
Contributor

One difference when running as an addon is that the active area is a menu instead of the text editor. Running a debugger, it looks like a uiBlock in the menu has a screwed up list of buttons, starting at a reasonable address and ending at 0x0000010200000000. Additionally, when we get to interface_handlers.cc:8823, the first button we iterate over acts just fine, but its prev and next fields are both set to 0x3f800001bf800001. These values probably aren't garbage, they're the same every time. The next iteration of the loop then tries to read from that address, causing a segfault. I don't know enough about what to expect here to know why this might be happening.

One difference when running as an addon is that the active area is a menu instead of the text editor. Running a debugger, it looks like a `uiBlock` in the menu has a screwed up list of buttons, starting at a reasonable address and ending at `0x0000010200000000`. Additionally, when we get to `interface_handlers.cc:8823`, the first button we iterate over acts just fine, but its `prev` and `next` fields are both set to `0x3f800001bf800001`. These values probably aren't garbage, they're the same every time. The next iteration of the loop then tries to read from that address, causing a segfault. I don't know enough about what to expect here to know why this might be happening.

Thanks for investigating @joshm-2. This seems to be caused by a pre-existing issue that was exposed by the addition of context.property. I'll commit a fix.

Thanks for investigating @joshm-2. This seems to be caused by a pre-existing issue that was exposed by the addition of `context.property`. I'll commit a fix.
Blender Bot added
Status
Resolved
and removed
Status
Confirmed
labels 2023-09-14 19:06: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
5 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#112299
No description provided.