Page MenuHome

Segfault with bmesh API on a mesh with a shape key
Closed, ResolvedPublicBUG

Description

System Information
Operating system: Linux (NixOS 20.03)
Graphics card: NVIDIA GeForce RTX 2070

Blender Version
Broken: 2.83, 2.90.0 alpha (2e52b3206cc6)
Worked: 2.82a and older

Short description of error

The following script crashes in Blender 2.83, but worked in previous versions:

import bpy
import bmesh
mesh = bpy.data.meshes.new("Test")
obj = bpy.data.objects.new("Test", mesh)
obj.shape_key_add(name="Basis")
bpy.context.scene.collection.objects.link(obj)
bpy.context.view_layer.objects.active = obj
bpy.ops.object.mode_set(mode="EDIT")
bm = bmesh.from_edit_mesh(obj.data)
vertex = bm.verts.new((2.0, 2.0, 2.0))
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.mode_set(mode='EDIT') # <-- crashes here
bpy.ops.object.mode_set(mode='OBJECT')

Removing obj.shape_key_add(name="Basis") makes the segfault disappear.

Here is a stack trace from gdb (from running blender -P ./script.py):

#0  0x0000000000fa8ed6 in BM_mesh_bm_from_me ()
#1  0x0000000000c7966e in BKE_mesh_to_bmesh_ex ()
#2  0x0000000000c796bb in BKE_mesh_to_bmesh ()
#3  0x00000000013aa97c in EDBM_mesh_make ()
#4  0x00000000013f25a9 in ED_object_editmode_enter_ex ()
#5  0x00000000013f292a in ?? ()
#6  0x0000000000ec6a93 in ?? ()
#7  0x0000000000ec6d07 in ?? ()
#8  0x0000000000ec720a in WM_operator_name_call_ptr ()
#9  0x00000000013f12ef in ?? ()
#10 0x0000000000ec6a93 in ?? ()
#11 0x0000000000ec7370 in WM_operator_call_py ()
#12 0x0000000001207303 in ?? ()
#13 0x000000000570f339 in _PyMethodDef_RawFastCallKeywords ()
#14 0x000000000570f3f5 in _PyCFunction_FastCallKeywords ()
#15 0x0000000000c11b20 in _PyEval_EvalFrameDefault ()
#16 0x00000000057c0d8c in _PyEval_EvalCodeWithName ()
#17 0x000000000570ecc0 in _PyFunction_FastCallDict ()
#18 0x000000000570ff0d in _PyObject_Call_Prepend ()
#19 0x000000000576b801 in ?? ()
#20 0x000000000570f514 in _PyObject_FastCallKeywords ()
#21 0x0000000000c0b4c5 in _PyEval_EvalFrameDefault ()
#22 0x00000000057c0d8c in _PyEval_EvalCodeWithName ()
#23 0x00000000057c0ebe in PyEval_EvalCodeEx ()
#24 0x00000000057c0eeb in PyEval_EvalCode ()
#25 0x00000000057f40e2 in PyRun_FileExFlags ()
#26 0x00000000011f3681 in ?? ()
#27 0x0000000000c135b8 in _start ()

Maybe this has something to do with https://developer.blender.org/D7818?

Exact steps for others to reproduce the error

  • In default scene go to the Text Editor
  • Copy and paste script above
  • Run script

Crash
Removing obj.shape_key_add(name="Basis") makes the segfault disappear.

Event Timeline

Germano Cavalcante (mano-wii) changed the task status from Needs Triage to Confirmed.Jun 9 2020, 7:35 PM
Germano Cavalcante (mano-wii) updated the task description. (Show Details)
Germano Cavalcante (mano-wii) changed the subtype of this task from "Report" to "Bug".

This crashes with the following steps too (not Python).

  • Enter edit-mode on the default cube.
  • Select all vertices and delete them.
  • Exit edit-mode.
  • Add a shape-key.
  • Exit edit mode.
  • Enter edit mode (crash).