Page MenuHome

Blender crash in bmesh.to_mesh() while using it to modify weights
Open, Needs Triage by DeveloperPublic

Description

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: rBdd904f67614b
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()

Details

Type
Bug

Event Timeline

This is where the crash occurs: