Page MenuHome

Using python to translate grease pencil vertices in edit mode causes crash
Closed, InvalidPublic

Description

System Information
Operating system: Arch Linux
Graphics card: GTX 1060

Blender Version
Broken: 2.80, d46d8e831ce

Exact steps for others to reproduce the error

  1. Delete the camera, cube, and light and create a grease pencil object
  2. Go to draw mode and draw a random stroke
  3. Go to edit mode and select all the grease pencil vertices
  4. Open a Text Editor area and run the following code... Blender will crash immediately:
import bpy

bpy.context.area.ui_type = 'VIEW_3D'
bpy.ops.transform.translate(value=(0, 0, 0))

Error Message

Writing: /tmp/untitled.crash.txt
Segmentation fault (core dumped)

Event Timeline

Jacques Lucke (JacquesLucke) lowered the priority of this task from 90 to 50.Dec 20 2018, 12:19 PM

Simply executing the script below in the text editor, also crashes Blender. No other setup needed.

import bpy
bpy.context.area.type = 'VIEW_3D'
bpy.ops.transform.translate(value=(0, 0, 0))

@Jacques Lucke (JacquesLucke) I can reproduce with --factory-startup, so it's not related to grease pencil.

Problem is here:

void setTransformViewMatrices(TransInfo *t)
{
	if (t->spacetype == SPACE_VIEW3D && t->ar && t->ar->regiontype == RGN_TYPE_WINDOW) {
		RegionView3D *rv3d = t->ar->regiondata;

		copy_m4_m4(t->viewmat, rv3d->viewmat);
		copy_m4_m4(t->viewinv, rv3d->viewinv);
		copy_m4_m4(t->persmat, rv3d->persmat);
		copy_m4_m4(t->persinv, rv3d->persinv);
		t->persp = rv3d->persp;
	}

rv3d is NULL.

Call stack extract:

memcpy() Line 459	Unknown
copy_m4_m4(float[4] * m1, const float[4] * m2) Line 93	C
setTransformViewMatrices(TransInfo * t) Line 246	C
initTransInfo(bContext * C, TransInfo * t, wmOperator * op, const wmEvent * event) Line 1647	C
initTransform(bContext * C, TransInfo * t, wmOperator * op, const wmEvent * event, int mode) Line 2291	C
transformops_data(bContext * C, wmOperator * op, const wmEvent * event) Line 373	C
transform_exec(bContext * C, wmOperator * op) Line 465	C
wm_operator_invoke(bContext * C, wmOperatorType * ot, wmEvent * event, PointerRNA * properties, ReportList * reports, const bool poll_only, bool use_last_properties) Line 1337	C
Bastien Montagne (mont29) claimed this task.

Eeeeek!

bpy.context.area.ui_type = 'VIEW_3D'

Seriously? You know you are changing the current active editor to 3D View with that, right? You cannot, absolutely cannot, do that in a py script and expect things to work... UI will simply not update quickly enough, and you'll call the transform operator with a completely broken context.

What you want to do here is to create a fake context to call your ops with, with all required data. See https://docs.blender.org/api/current/bpy.ops.html#overriding-context