Page MenuHome

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

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...

Sebastian Parborg (zeddb) triaged this task as Needs Information from User priority.Feb 5 2019, 8:59 PM

@Philipp Oeser (lichtwerk) still planning to look into this?

Jacques Lucke (JacquesLucke) raised the priority of this task from Needs Information from User to Needs Triage by Developer.Mar 7 2019, 3:32 PM
Sebastian Parborg (zeddb) triaged this task as Confirmed, Medium priority.Sun, Mar 31, 9:50 PM

Backtrace:

Thread 1 "blender" received signal SIGSEGV, Segmentation fault.
0x00007fffeba89c17 in ?? () from /lib64/libc.so.6
(gdb) bt
#0  0x00007fffeba89c17 in ?? () from /lib64/libc.so.6
#1  0x00005555592b8755 in copy_m4_m4 (m1=0x7fffbc6a5a2c, m2=0x40) at /home/zed/prog/blender/source/blender/blenlib/intern/math_matrix.c:88
#2  0x0000555558015a95 in setTransformViewMatrices (t=0x7fffbc6a5708) at /home/zed/prog/blender/source/blender/editors/transform/transform.c:235
#3  0x00005555580762e9 in initTransInfo (C=0x7fffdc058188, t=0x7fffbc6a5708, op=0x7fffbc5dfec8, event=0x0)
    at /home/zed/prog/blender/source/blender/editors/transform/transform_generics.c:1681
#4  0x000055555801b1ac in initTransform (C=0x7fffdc058188, t=0x7fffbc6a5708, op=0x7fffbc5dfec8, event=0x0, mode=1)
    at /home/zed/prog/blender/source/blender/editors/transform/transform.c:2340
#5  0x0000555558086e01 in transformops_data (C=0x7fffdc058188, op=0x7fffbc5dfec8, event=0x0)
    at /home/zed/prog/blender/source/blender/editors/transform/transform_ops.c:370
#6  0x0000555558087092 in transform_exec (C=0x7fffdc058188, op=0x7fffbc5dfec8) at /home/zed/prog/blender/source/blender/editors/transform/transform_ops.c:463
#7  0x0000555557e63e48 in wm_operator_invoke (C=0x7fffdc058188, ot=0x7fffd6dfab88, event=0x0, properties=0x7fffffffcd90, reports=0x7fffb97fabb8,
    poll_only=false, use_last_properties=true) at /home/zed/prog/blender/source/blender/windowmanager/intern/wm_event_system.c:1353
#8  0x0000555557e6464b in wm_operator_call_internal (C=0x7fffdc058188, ot=0x7fffd6dfab88, properties=0x7fffffffcd90, reports=0x7fffb97fabb8, context=6,
    poll_only=false, event=0x0) at /home/zed/prog/blender/source/blender/windowmanager/intern/wm_event_system.c:1586
#9  0x0000555557e64899 in WM_operator_call_py (C=0x7fffdc058188, ot=0x7fffd6dfab88, context=6, properties=0x7fffffffcd90, reports=0x7fffb97fabb8,
    is_undo=false) at /home/zed/prog/blender/source/blender/windowmanager/intern/wm_event_system.c:1664
#10 0x00005555585af25d in pyop_call (UNUSED_self=<module at remote 0x7fffd7068688>, args=Python Exception <class 'gdb.error'> No type named PyUnicodeObject.:
)