Page MenuHome

bmesh.ops.bevel crash (Segfault)
Closed, ResolvedPublic

Description

System Information
Linux mint 18 / Nvidia 1070

Blender Version
Broken: 2.8 10bab568d33 (2018-11-14)
Worked:
2.79x

Short description of error
bmesh.ops.bevel crash Segfault

Exact steps for others to reproduce the error
Based on a (as simple as possible) attached .blend file with minimum amount of steps

Load factory, then run from py console

import bmesh
bpy.ops.object.mode_set(mode="EDIT")
bm = bmesh.from_edit_mesh(C.object.data)
geom = bm.edges[:]
bmesh.ops.bevel(bm,
                    geom=geom,
                    offset=0.1,
                    offset_type='OFFSET',
                    segments=1, 
                    profile=0.5,
                    vertex_only=False,
                    clamp_overlap=False,
                    material=-1)

Debug report:
BLI_assert failed: /home/stephen/blender-28-git/blender/source/blender/python/bmesh/bmesh_py_types.c:3798, BPy_BMElem_CreatePyObject(), at '0'

Blender 2.80 (sub 30), Commit date: 2018-11-14 16:15, Hash 10bab568d33

bpy.ops.object.editmode_toggle() # Operator

backtrace

/home/stephen/blender-28-git/build_linux_full/bin/blender(BLI_system_backtrace+0x33) [0x555a751abc93]
/home/stephen/blender-28-git/build_linux_full/bin/blender(+0xc1d4d0) [0x555a7471a4d0]
/lib/x86_64-linux-gnu/libc.so.6(+0x3ef20) [0x7ff4f3c30f20]
/home/stephen/blender-28-git/build_linux_full/bin/blender(BM_mesh_bevel+0x1ee7) [0x555a74ce2fd7]
/home/stephen/blender-28-git/build_linux_full/bin/blender(bmo_bevel_exec+0x1ee) [0x555a74cf28de]
/home/stephen/blender-28-git/build_linux_full/bin/blender(BMO_op_exec+0x31) [0x555a74cc0c41]
/home/stephen/blender-28-git/build_linux_full/bin/blender(BPy_BMO_call+0x1c3) [0x555a74b1d0f3]
/home/stephen/blender-28-git/build_linux_full/bin/blender(_PyObject_FastCallKeywords+0x11f) [0x555a7638d18f]
/home/stephen/blender-28-git/build_linux_full/bin/blender(_PyEval_EvalFrameDefault+0x3fc4) [0x555a74711b54]
/home/stephen/blender-28-git/build_linux_full/bin/blender(_PyEval_EvalCodeWithName+0xa5a) [0x555a7644f14a]
/home/stephen/blender-28-git/build_linux_full/bin/blender(PyEval_EvalCode+0x23) [0x555a7644f223]
/home/stephen/blender-28-git/build_linux_full/bin/blender(+0x294f4c9) [0x555a7644c4c9]
/home/stephen/blender-28-git/build_linux_full/bin/blender(_PyCFunction_FastCallKeywords+0x28a) [0x555a7638d5ca]
/home/stephen/blender-28-git/build_linux_full/bin/blender(_PyEval_EvalFrameDefault+0x8d1e) [0x555a747168ae]
/home/stephen/blender-28-git/build_linux_full/bin/blender(+0xc0faa7) [0x555a7470caa7]
/home/stephen/blender-28-git/build_linux_full/bin/blender(_PyEval_EvalFrameDefault+0x628e) [0x555a74713e1e]
/home/stephen/blender-28-git/build_linux_full/bin/blender(_PyEval_EvalCodeWithName+0xa5a) [0x555a7644f14a]
/home/stephen/blender-28-git/build_linux_full/bin/blender(_PyFunction_FastCallKeywords+0x8f) [0x555a7638cbff]
/home/stephen/blender-28-git/build_linux_full/bin/blender(_PyEval_EvalFrameDefault+0x628e) [0x555a74713e1e]
/home/stephen/blender-28-git/build_linux_full/bin/blender(+0xc0faa7) [0x555a7470caa7]
/home/stephen/blender-28-git/build_linux_full/bin/blender(_PyEval_EvalFrameDefault+0x628e) [0x555a74713e1e]
/home/stephen/blender-28-git/build_linux_full/bin/blender(+0xc0faa7) [0x555a7470caa7]
/home/stephen/blender-28-git/build_linux_full/bin/blender(_PyEval_EvalFrameDefault+0x72b5) [0x555a74714e45]
/home/stephen/blender-28-git/build_linux_full/bin/blender(+0xc0faa7) [0x555a7470caa7]
/home/stephen/blender-28-git/build_linux_full/bin/blender(_PyFunction_FastCallDict+0x2b7) [0x555a7638cb57]
/home/stephen/blender-28-git/build_linux_full/bin/blender(+0xfde724) [0x555a74adb724]
/home/stephen/blender-28-git/build_linux_full/bin/blender(+0x1627956) [0x555a75124956]
/home/stephen/blender-28-git/build_linux_full/bin/blender(+0xc226a6) [0x555a7471f6a6]
/home/stephen/blender-28-git/build_linux_full/bin/blender(+0xc25755) [0x555a74722755]
/home/stephen/blender-28-git/build_linux_full/bin/blender(+0xc25cf5) [0x555a74722cf5]
/home/stephen/blender-28-git/build_linux_full/bin/blender(+0xc265ac) [0x555a747235ac]
/home/stephen/blender-28-git/build_linux_full/bin/blender(wm_event_do_handlers+0x5fa) [0x555a74723f2a]
/home/stephen/blender-28-git/build_linux_full/bin/blender(WM_main+0x20) [0x555a7471afa0]
/home/stephen/blender-28-git/build_linux_full/bin/blender(main+0x35a) [0x555a746f372a]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7) [0x7ff4f3c13b97]
/home/stephen/blender-28-git/build_linux_full/bin/blender(_start+0x2a) [0x555a74716bfa]

Details

Type
Bug

Event Timeline

Bastien Montagne (mont29) triaged this task as Confirmed priority.Mon, Nov 26, 9:39 PM
Bastien Montagne (mont29) edited projects, added Mesh Modeling; removed BF Blender.

@Howard Trickey (howardt) issue is that no vert is tagged, so bevel_vert_construct() is never called on any vert, and vert hash is empty… Will let you decide how to fix that. ;)

Might be lack of vertex/edges/faces select state of solidify output ?
Following code was working under 2.79:
(input geometry is a plane in edit mode)

import bmesh

bm = bmesh.from_edit_mesh(C.object.data)

geom = bm.faces[:]
verts = bm.verts[:]
edges = bm.edges[:]
bmesh.ops.solidify(bm, geom=geom, thickness=0.1)
for v in verts:
    v.co.z = 0.0

# bevel
for v in bm.verts:
    v.select = True

for v in verts:
    v.select = False

for v in bm.edges:
    v.select = True

for v in edges:
    v.select = False

geom = [v for v in bm.verts if v.select]
geom.extend([v for v in bm.edges if v.select])
bmesh.ops.bevel(bm,
    geom=geom,
    offset=0.05,
    offset_type='OFFSET',
    segments=1, 
    profile=0.5,
    vertex_only=False,
    clamp_overlap=False,
    material=-1,
    loop_slide=True,
    mark_seam=False,
    mark_sharp=False,
    strength=0.5,
    hnmode='FACE')

The immediate problem was that no verts were in the input geometry, and code assumed that if edges were there then verts were there. The code in the second update added the verts. But I fixed the code to add the verts from all edges explicitly so that this would no longer be necessary.

But then it crashed again because the update to do normals hardening had added an internal 'slot' containing some output normals in order to do hardening after the op ran. And then Python crashed trying to convert them into elements because the normals were not elements. I fixed that (though leaving a memory leak) and ran into yet another problem when switching back into 3d view mode - it crashes because of some inconsistency in the data the GPU uses to draw. The currently submitted code is in that state, so still not usable. i will try to figure out how to fix that.

Fixing the memory leak I think is best done in another way. Really, the normal hardening should happen inside the bmesh_bevel routine itself (otherwise the Op cannot do hardening!) and the whole idea of passing back normals through a slot can go away. But that is not a quick fix. But I hope to fix it soon.

Howard Trickey (howardt) closed this task as Resolved.Wed, Nov 28, 2:55 PM

OK, so the crash was because one also needs to do a bmesh.update_edit_mesh(C.object.data) after running the above commands, and it is documented that one needs to do so. It all seems to work fine (though without hardening normals, if that is specified in the arguments) now.

So this bug is fixed, modulo the memory leak due to the code's weird use of a normals.out slot. I could add a flag to the BMSlot stuff to optionally have the free of a GHash also free the contents. But would rather not as I believe the correct thing to do is to refactor the code to remove the use of that slot altogether and use common code for hardening normals in both the modifier and the edit tool (right now they are separately implemented, and each has separate bugs). That will also fix the problem that runnning the op by itself will not actually hardent normals, if that is specified in the arguments.
I'll file another bug and assign it to me for that task.