Scripting: undo after mesh.separate causes crash #106248

Open
opened 2023-03-29 00:35:33 +02:00 by Scurest · 8 comments
Contributor

System Information
Operating system: Linux

Blender Version
Latest tested: blender-3.5.0-beta+v35.f23e3c7f04f3-linux.x86_64-release
Earliest tested: blender-3.1.2-linux-x64

Short description of error
Trying to undo bpy.ops.mesh.separate(type='MATERIAL') in a script crashes Blender.

Exact steps for others to reproduce the error

  1. Create a cube and two materials. Go to edit mode and assign some faces to both materials. Go back to object mode.

    A cube with white and red materials

  2. Open the Text Editor and run this script

    import bpy
    bpy.ops.ed.undo_push( message = "temp" )
    bpy.ops.mesh.separate( type = 'MATERIAL' )
    bpy.ops.ed.undo()
    
  3. Crash (segmentation fault).

Somewhat mysteriously if I save just before running the script, close Blender, then reopen the .blend and then run the script, I get non-determinstic results (sometimes the undo does nothing, sometimes the white part is gone). The only consistent way I found to get a crash was to create the cube from scratch every time. So no .blend is attached to this issue.

**System Information** Operating system: Linux **Blender Version** Latest tested: blender-3.5.0-beta+v35.f23e3c7f04f3-linux.x86_64-release Earliest tested: blender-3.1.2-linux-x64 **Short description of error** Trying to undo `bpy.ops.mesh.separate(type='MATERIAL')` in a script crashes Blender. **Exact steps for others to reproduce the error** 1. Create a cube and two materials. Go to edit mode and assign some faces to both materials. Go back to object mode. ![A cube with white and red materials](/attachments/8054c887-97b8-4a42-a26d-7a7064ec1335) 2. Open the Text Editor and run this script ```py import bpy bpy.ops.ed.undo_push( message = "temp" ) bpy.ops.mesh.separate( type = 'MATERIAL' ) bpy.ops.ed.undo() ``` 3. Crash (segmentation fault). Somewhat mysteriously if I save just before running the script, close Blender, then reopen the .blend and then run the script, I get non-determinstic results (sometimes the undo does nothing, sometimes the white part is gone). The only consistent way I found to get a crash was to create the cube from scratch every time. So no .blend is attached to this issue.
Scurest added the
Priority
Normal
Type
Report
Status
Needs Triage
labels 2023-03-29 00:35:34 +02:00
Iliya Katushenock added the
Interest
Modeling
label 2023-03-29 03:32:09 +02:00
Member

Can confirm

Can confirm
Pratik Borhade added
Status
Confirmed
Interest
Undo
Module
Python API
and removed
Status
Needs Triage
labels 2023-03-29 07:32:16 +02:00
Philipp Oeser added the
Interest
Core
label 2023-06-06 10:32:15 +02:00
Member

@mont29 : does this crash sound like High priority to you?

@mont29 : does this crash sound like High priority to you?

Please always attach a blendfile, this makes reproducing way simpler and faster.

Also, the issue here is getting out of Editmode, then running the script.

106248.blend

Please always attach a blendfile, this makes reproducing way simpler and faster. Also, the issue here is getting out of Editmode, then running the script. [106248.blend](/attachments/29766a5a-f35b-41b2-ac7d-95a7c3b13734)
Member

Please always attach a blendfile, this makes reproducing way simpler and faster.

This was mentioned here

Somewhat mysteriously if I save just before running the script, close Blender, then reopen the .blend and then run the script, I get non-determinstic results (sometimes the undo does nothing, sometimes the white part is gone). The only consistent way I found to get a crash was to create the cube from scratch every time. So no .blend is attached to this issue.

Also, the issue here is getting out of Editmode, then running the script.

Sorry if I dont get this right: what does this mean? This is then still wrong, see the comment above (non-determinstic results)

> Please always attach a blendfile, this makes reproducing way simpler and faster. This was mentioned here >Somewhat mysteriously if I save just before running the script, close Blender, then reopen the .blend and then run the script, I get non-determinstic results (sometimes the undo does nothing, sometimes the white part is gone). The only consistent way I found to get a crash was to create the cube from scratch every time. So no .blend is attached to this issue. > Also, the issue here is getting out of Editmode, then running the script. Sorry if I dont get this right: what does this mean? This is then still wrong, see the comment above (non-determinstic results)

It is not wrong, open that blendfile, go in/out of Edit mode, run the script, crash

It is not wrong, open that blendfile, go in/out of Edit mode, run the script, crash
Member

It is not wrong, open that blendfile, go in/out of Edit mode, run the script, crash

Ah, OK, sorry for my confusion

> It is not wrong, open that blendfile, go in/out of Edit mode, run the script, crash Ah, OK, sorry for my confusion

@scurest I would consider this case as unsupported tbh.

Thing is, running the script from the text editor is already running an operator, so all the operator calls you are doing here are done as sub-level calls of the main operator.

The WindowManager handles undo automatically for operators, ensuring that undo steps are only created after executing top-level operators, and none of their potential operators sub-calls inside the top-level one.

So calling things like bpy.ops.ed.undo_push and bpy.ops.ed.undo here is enforcing undo stack operations in a context which does not support them.

In general, usage of bpy.ops.ed.undo related operators should be very carefully weighted, these should almost never be needed in a normal usage case.

@scurest I would consider this case as unsupported tbh. Thing is, running the script from the text editor is already running an operator, so all the operator calls you are doing here are done as sub-level calls of the main operator. The WindowManager handles undo automatically for operators, ensuring that undo steps are only created after executing top-level operators, and none of their potential operators sub-calls inside the top-level one. So calling things like `bpy.ops.ed.undo_push` and `bpy.ops.ed.undo` here is enforcing undo stack operations in a context which does not support them. In general, usage of `bpy.ops.ed.undo` related operators should be very carefully weighted, these should almost never be needed in a normal usage case.
Author
Contributor

Okay. Can it produce an error instead of crashing?

Okay. Can it produce an error instead of crashing?
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
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#106248
No description provided.