Page MenuHome

100% repro errors and crash using BMesh.free() in conjunction with bmesh.from_edit_mesh() and bmesh.update_edit_mesh()
Closed, ArchivedPublic

Description

System Information
Linux Mint 16, nvidia GTX 460 (not sure if relevant

Blender Version
Broken: 2.70-RC1 and 2.69
Worked: ?

Python snippet:

import bmesh, bpy
mesh = bpy.context.active_object.data
bm = bmesh.from_edit_mesh(mesh)

for edge in bm.edges:
    edge.select = False

bmesh.update_edit_mesh(mesh)
bm.free()

REPRO STEPS:

  1. Run script, it works
  2. Run script again, check console
  3. Run script again, check console
  4. Tab out of edit mode, then back in
  5. Run script again, crashes Blender
  6. If bm.free() is removed, no errors

Event Timeline

Jean Ayer (vrav) raised the priority of this task from to 90.
Jean Ayer (vrav) updated the task description. (Show Details)
Jean Ayer (vrav) edited a custom field.
Jean Ayer (vrav) added a subscriber: Jean Ayer (vrav).

Attaching 27RC_bmesh_crash.blend with snippet loaded and ready to load.

Error output data included, here for convenience...

After first fail:

Traceback (most recent call last):
  File "/home/vrav/Documents/27RC_bmesh_crash.blend/Text", line 6, in <module>
ReferenceError: BMesh data of type BMesh has been removed
Error: Python script fail, look in the console for now...

After second fail:

Traceback (most recent call last):
  File "/home/vrav/Documents/27RC_bmesh_crash.blend/Text", line 6, in <module>
AttributeError: 'bytes' object has no attribute 'edges'
Error: Python script fail, look in the console for now...

Segmentation fault crash dump:

 Blender 2.70 (sub 0), Commit date: 2014-03-05 18:37, Hash 19f7f9a
bpy.ops.object.editmode_toggle()  # Operator
bpy.ops.text.run_script()  # Operator
bpy.ops.text.run_script()  # Operator
Python script fail, look in the console for now...  # Error
bpy.ops.text.run_script()  # Operator
Python script fail, look in the console for now...  # Error
bpy.ops.object.editmode_toggle()  # Operator
bpy.ops.object.editmode_toggle()  # Operator

 backtrace
./blender() [0xfbe704]
./blender() [0xfbe95a]
/lib/x86_64-linux-gnu/libc.so.6(+0x36ff0) [0x7f971bc53ff0]
./blender(PyObject_Malloc+0x5c) [0x2bec96c]
./blender(_PyObject_New+0xd) [0x2be9bbd]
./blender(BPy_BMEdge_CreatePyObject+0x74) [0x1864db4]
./blender(PyEval_EvalFrameEx+0x327f) [0x2c501ff]
./blender(PyEval_EvalCodeEx+0x83b) [0x2c4ceab]
./blender(PyEval_EvalCode+0x3b) [0x2c4cf7b]
./blender() [0x18571aa]
./blender() [0x120757c]
./blender() [0xfda062]
./blender() [0xfda560]
./blender() [0x129cb3a]
./blender() [0x12ac22b]
./blender() [0xfdb8c5]
./blender() [0xfdbbd6]
./blender(wm_event_do_handlers+0x19a) [0xfdbeca]
./blender(WM_main+0x18) [0xfc5fb8]
./blender(main+0x501) [0xfc0f8a]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7f971bc3ede5]
./blender() [0xedace5]

#Same thing:

import bmesh, bpy
mesh=bpy.context.object.data

bm = bmesh.from_edit_mesh(mesh)

#sort verts after z coordinate
sort = sorted(bm.verts, key=lambda v: v.co.z)

#select lowest
sort[0].select = True

bmesh.update_edit_mesh(mesh)

bm.free()


'''
This codes works the first time it is run.
Produces an error on subsequent runs.
Then crashes on autocomplete in the console.
'''
Bastien Montagne (mont29) changed the task status from Unknown Status to Archived.Mar 11 2014, 9:48 PM
Bastien Montagne (mont29) claimed this task.

bmesh.from_edit_mesh() does not create a bmesh, it returns the one associated with given mesh (that’s why mesh has to be in EditMode, else it has no bmesh associated with it). So the bmesh you get must never be freed!!! This is internal Blender data, created when entering EditMode and freed when leaving it.

Not a bug, closing.

thanks for clarification.
Sorry for false positive