Page MenuHome

Segmentation fault when selecting context.area.type before applying operator (scripting)
Open, Needs TriagePublic

Description

System Information
OS: Ubuntu 16.04.4 LTS
HW: Dell XPS 9550 notebook, using Intel HD GPU (nvidia deactivted)

Blender Version
Broken: 2.8, Hash: cc69831796
Broken: 2.79, Hash: f4dc9f9d68b

Short description of error
Executing the operator bpy.ops.transform.translate causes a crash if bpy.context.area.type is set manually before.

Backtrace
./blender(BLI_system_backtrace+0x20) [0x1a6c700]
./blender() [0x1078395]
/lib/x86_64-linux-gnu/libc.so.6(+0x354b0) [0x7fd7fe43b4b0]
./blender(copy_m4_m4+0) [0x1a4bbe0]
./blender(setTransformViewMatrices+0x90) [0x11c4ef0]
./blender(initTransInfo+0x582) [0x11df282]
./blender(initTransform+0xd4) [0x11c7fa4]
./blender() [0x11e6c6b]
./blender() [0x11e6fc1]
./blender() [0x107fbfa]
./blender(WM_operator_call_py+0x6b) [0x10804ab]
./blender() [0x147d280]
./blender(PyCFunction_Call+0xb9) [0x2e9d579]
./blender(PyEval_EvalFrameEx+0x81ec) [0x2f16d7c]
./blender() [0x2f1869e]
./blender(PyEval_EvalCodeEx+0x23) [0x2f18773]
./blender() [0x2e79746]
./blender(PyObject_Call+0x5c) [0x2e4f06c]
./blender() [0x2e68e34]
./blender(PyObject_Call+0x5c) [0x2e4f06c]
./blender() [0x2eb9d7f]
./blender(PyObject_Call+0x5c) [0x2e4f06c]
./blender(PyEval_EvalFrameEx+0x3812) [0x2f123a2]
./blender() [0x2f1869e]
./blender(PyEval_EvalCode+0x1f) [0x2f1879f]
./blender() [0x146966a]
./blender() [0x114170e]
./blender() [0x107fbfa]
./blender() [0x107ffe2]
./blender() [0x125cedb]
./blender() [0x126d5a9]
./blender() [0x10814ec]
./blender() [0x1081958]
./blender(wm_event_do_handlers+0x1d4) [0x1081c64]
./blender(WM_main+0x18) [0x1078f78]
./blender(main+0x3f8) [0x1016a38]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7fd7fe426830]
./blender() [0x10752ee]

Exact steps for others to reproduce the error
Running the following script causes the crash:

import bpy
import bmesh

# Create object
bpy.ops.mesh.primitive_plane_add(radius=1, view_align=False, enter_editmode=False, location=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))

# Enter edit mode
bpy.context.area.type = 'VIEW_3D' # If this is not set, crash does not occur
bpy.ops.object.mode_set(mode='EDIT', toggle=False)

# Modify vertices
mesh = bmesh.from_edit_mesh(bpy.context.active_object.data)
mesh.verts.ensure_lookup_table()
mesh.verts[0].select = True

# Next call causes crash:
bpy.ops.transform.translate(value=(0, 0, 1), constraint_axis=(False, False, True),
                            constraint_orientation='GLOBAL', mirror=False, proportional='ENABLED',
                            proportional_edit_falloff='SHARP')

Details

Type
Bug

Event Timeline

I think what you want to do is override the context and pass that to the operator

import bpy
import bmesh

# Create object
bpy.ops.mesh.primitive_plane_add(radius=1, view_align=False, enter_editmode=False, location=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))

# Enter edit mode
bpy.ops.object.mode_set(mode='EDIT', toggle=False)

# Modify vertices
mesh = bmesh.from_edit_mesh(bpy.context.active_object.data)
mesh.verts.ensure_lookup_table()
mesh.verts[0].select = True

# Override context
win      = bpy.context.window
scr      = win.screen
areas3d  = [area for area in scr.areas if area.type == 'VIEW_3D']
region   = [region for region in areas3d[0].regions if region.type == 'WINDOW']
override = {'window':win,
            'screen':scr,
            'area'  :areas3d[0],
            'region':region[0],
            'scene' :bpy.context.scene,
            }

# call with override context:
bpy.ops.transform.translate(override, value=(0, 0, 1), constraint_axis=(False, False, True),
                            constraint_orientation='GLOBAL', mirror=False, proportional='ENABLED',
                            proportional_edit_falloff='SHARP')

see API reference

having a look at the crash later...