Blender crash in bmesh.to_mesh() while using it to modify weights (fixed in 3.6, only relevant for 3.3 LTS) #71585

Open
opened 2019-11-14 21:29:50 +01:00 by Erik Abrahamsson · 11 comments

System Information
Operating system: Windows-10-10.0.18362 64 Bits
Graphics card: GeForce GTX 1070/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 431.70

Blender Version
Broken: version: 2.82 (sub 1), branch: master, commit date: 2019-10-27 17:59, hash: dd904f6761
Worked: (optional)

Short description of error
Crash in bmesh.to_mesh() if using it to modify weights in weightpainting while playing animation

Exact steps for others to reproduce the error
*Remove any lights or cameras, keep just one cube in the scene (for the simple script to work).
*Subdivide it 5 times and apply the modifier.
*Add the script below to the script editor and run it
*Go to weight paint mode for the cube
*Run the animation and try to paint. If you just click the left mouse button it will paint a dot and the script will work, but if you hold and drag, Blender crashes.

import bpy, bmesh


def add_handler():
    # remove existing handlers
    old_handlers = []
    for h in bpy.app.handlers.frame_change_post:
        if "paint_test" in str(h):
            old_handlers.append(h)
    for h in old_handlers: bpy.app.handlers.frame_change_post.remove(h)
    # add new handler
    bpy.app.handlers.frame_change_post.append(paint_test)

def paint_test(scene):
    for ob in scene.objects:
        me = ob.data
        
        print(str(scene.frame_current) + ": Creating Bmesh")
        bm = bmesh.new()
        bm.from_mesh(me)
        
        group_index = ob.vertex_groups.active_index
        dvert_lay = bm.verts.layers.deform.active
            
        for vert in bm.verts:
            dvert = vert[dvert_lay]
            try: dvert[group_index] -= 0.1
            except: pass            
        
        print(str(scene.frame_current) + ": Writing Bmesh")
        bm.to_mesh(me)
        bm.free()
        
add_handler()
**System Information** Operating system: Windows-10-10.0.18362 64 Bits Graphics card: GeForce GTX 1070/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 431.70 **Blender Version** Broken: version: 2.82 (sub 1), branch: master, commit date: 2019-10-27 17:59, hash: `dd904f6761` Worked: (optional) **Short description of error** Crash in bmesh.to_mesh() if using it to modify weights in weightpainting while playing animation **Exact steps for others to reproduce the error** *Remove any lights or cameras, keep just one cube in the scene (for the simple script to work). *Subdivide it 5 times and apply the modifier. *Add the script below to the script editor and run it *Go to weight paint mode for the cube *Run the animation and try to paint. If you just click the left mouse button it will paint a dot and the script will work, but if you hold and drag, Blender crashes. ``` import bpy, bmesh def add_handler(): # remove existing handlers old_handlers = [] for h in bpy.app.handlers.frame_change_post: if "paint_test" in str(h): old_handlers.append(h) for h in old_handlers: bpy.app.handlers.frame_change_post.remove(h) # add new handler bpy.app.handlers.frame_change_post.append(paint_test) def paint_test(scene): for ob in scene.objects: me = ob.data print(str(scene.frame_current) + ": Creating Bmesh") bm = bmesh.new() bm.from_mesh(me) group_index = ob.vertex_groups.active_index dvert_lay = bm.verts.layers.deform.active for vert in bm.verts: dvert = vert[dvert_lay] try: dvert[group_index] -= 0.1 except: pass print(str(scene.frame_current) + ": Writing Bmesh") bm.to_mesh(me) bm.free() add_handler() ```
Author
Member

Added subscriber: @erik85

Added subscriber: @erik85
Author
Member

This is where the crash occurs:
bild.png

This is where the crash occurs: ![bild.png](https://archive.blender.org/developer/F8136231/bild.png)
Member

Added subscriber: @JacquesLucke

Added subscriber: @JacquesLucke
Member

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

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

I can reproduce the issue. Not sure if there is an easy fix. You could try to update the vertex weights without bmesh.

I can reproduce the issue. Not sure if there is an easy fix. You could try to update the vertex weights without bmesh.

Added subscribers: @Sergey, @ideasman42, @mont29

Added subscribers: @Sergey, @ideasman42, @mont29

@JacquesLucke (and obviously @erik85) please always attach minimal .blend file to help reproducing the issue, this saves time for everybody who would want to investigate further.

That handler callback will basically re-allocate all data inside of the Mesh data-block, not knowing enough about handler system to be sure without actual investigation, but I would bet that that is not supposed to happen (and hence not expected to work), @Sergey, @ideasman42 ?

@JacquesLucke (and obviously @erik85) please always attach minimal .blend file to help reproducing the issue, this saves time for everybody who would want to investigate further. That handler callback will basically re-allocate all data inside of the Mesh data-block, not knowing enough about handler system to be sure without actual investigation, but I would bet that that is not supposed to happen (and hence not expected to work), @Sergey, @ideasman42 ?
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Not sure what I am doing "wrong", but this is not crashing for me:
#71585.blend

Not sure what I am doing "wrong", but this is **not** crashing for me: [#71585.blend](https://archive.blender.org/developer/F8279825/T71585.blend)
Member

@lichtwerk, it crashes for me when I add one more subdivision level to the cube.

@lichtwerk, it crashes for me when I add one more subdivision level to the cube.
Philipp Oeser removed the
Interest
Python API
label 2023-02-10 09:04:44 +01:00
Member

Can still repro this in 3.5.1, but in 3.6 onwards, this seems to be fixed.

The fix happened somewhere between bad dc63f75837 and good 8dae058768 (in case we still want to backport this to 3.3 LTS).

Will mark as an 3.3 only issue then.

Can still repro this in 3.5.1, but in 3.6 onwards, this seems to be fixed. The fix happened somewhere between bad dc63f75837f2 and good 8dae0587686d (in case we still want to backport this to 3.3 LTS). Will mark as an 3.3 only issue then.
Philipp Oeser changed title from Blender crash in bmesh.to_mesh() while using it to modify weights to Blender crash in bmesh.to_mesh() while using it to modify weights (fixed in 3.6, only relevant for 3.3 LTS) 2024-03-07 16:38:36 +01:00
Philipp Oeser added this to the 3.3 LTS milestone 2024-03-07 16:38:40 +01: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
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#71585
No description provided.