Using python to translate grease pencil vertices in edit mode causes crash #59654

Closed
opened 2018-12-20 04:58:59 +01:00 by Daniel Oakey · 10 comments

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

crash.gif

Error Message

Writing: /tmp/untitled.crash.txt
Segmentation fault (core dumped)
**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)) ``` ![crash.gif](https://archive.blender.org/developer/F6012384/crash.gif) **Error Message** ``` Writing: /tmp/untitled.crash.txt Segmentation fault (core dumped) ```
Author

Added subscriber: @doakey3

Added subscriber: @doakey3
Member

Added subscriber: @JacquesLucke

Added subscriber: @JacquesLucke
Member

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))
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)) ```

Added subscriber: @antoniov

Added subscriber: @antoniov

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

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

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

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

Added subscriber: @mont29

Added subscriber: @mont29

Changed status from 'Confirmed' to: 'Archived'

Changed status from 'Confirmed' to: 'Archived'
Bastien Montagne self-assigned this 2020-02-17 16:15:01 +01:00

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

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
Sign in to join this conversation.
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#59654
No description provided.