2
$\begingroup$

I post here since I don't think it's a bug but something I could have done the wrong way...

So I have this script (copy-pasted from somewhere I don't remember, but this is the same I would have done reading the doc) :

def createMesh(name, origin, verts, edges, faces):
    me = bpy.data.meshes.new(name+'Mesh')
    ob = bpy.data.objects.new(name, me)
    ob.location = origin
    ob.show_name = True
    bpy.context.scene.objects.link(ob)
    me.from_pydata(verts, edges, faces)
    me.update(calc_edges=True)
    return ob

This is the full script, after executing it on the conole, if I try to switch to edit mode, then, blender crashes :

def sumInterval(it):
    s = 0
    for x in it:
        yield s, x
        s += x

T =  [

[ [ [ 2.7082256823778, -29.756011754274, 11.0 ], [ -5.170249427219, 29.321890527704, 0.0 ] ], [ [ -2.4620193839073, -0.43412045761943, 11.0 ], [ -5.170240696852, 29.321892067104, 0.0 ] ], [ [ -2.4620193839073, -0.43412045761943, 11.0 ], [ -5.1702409665746, 29.321893596777, 0.0 ] ], [ [ -7.6322559863329, 28.887773908675, 11.0 ], [ -5.1702322362062, 29.321895136175, 0.0 ] ], [ [ 7.6322641819715, -28.887769401073, 11.0 ], [ -5.1702491687653, 29.321889061942, 0.0 ] ], [ [ 2.4620193839073, 0.4341204315424, 11.0 ], [ -5.1702404383987, 29.321890601343, 0.0 ] ], [ [ 2.4620193839073, 0.4341204315424, 11.0 ], [ -5.1702407085707, 29.321892133564, 0.0 ] ], [ [ -2.7082169651985, 29.756013333797, 11.0 ], [ -5.1702319782027, 29.321893672962, 0.0 ] ] ]
,

[ [ [ -7.6322559863329, -28.887773886323, 0.0 ], [ 5.1702322362063, 29.321895136175, 0.0 ] ], [ [ -2.4620193839073, 0.43412047997117, 0.0 ], [ 5.1702409665746, 29.321893596777, 0.0 ] ], [ [ -2.4620193839073, 0.43412047997117, 0.0 ], [ 5.1702406974891, 29.321892070717, 0.0 ] ], [ [ 2.7082256823778, 29.756011780351, 0.0 ], [ 5.170249427856, 29.321890531317, 0.0 ] ], [ [ -2.7082169651985, -29.75601330772, 0.0 ], [ 5.1702319775657, 29.321893669349, 0.0 ] ], [ [ 2.4620193839073, -0.43412040919065, 0.0 ], [ 5.1702407079336, 29.321892129951, 0.0 ] ], [ [ 2.4620193839073, -0.43412040919065, 0.0 ], [ 5.1702404383987, 29.321890601343, 0.0 ] ], [ [ 7.6322641819715, 28.887769423425, 0.0 ], [ 5.1702491687653, 29.321889061942, 0.0 ] ] ]
,

[ [ [ -7.8059038707809, -29.872581691038, 0.0 ], [ 0.17364788444799, 0.98480780471457, 0.0 ] ], [ [ -7.6322559863329, -28.887773886323, 0.0 ], [ 0.17364788444799, 0.98480780471457, 0.0 ] ], [ [ 2.7082256823778, 29.756011780351, 0.0 ], [ 0.17364847088584, 0.98480770130976, 0.0 ] ], [ [ 2.8818741532637, 30.740819481661, 0.0 ], [ 0.17364847088584, 0.98480770130976, 0.0 ] ], [ [ -2.8818648496465, -30.740821112435, 0.0 ], [ 0.17364788444799, 0.98480780471457, 0.0 ] ], [ [ -2.7082169651985, -29.75601330772, 0.0 ], [ 0.17364788444799, 0.98480780471457, 0.0 ] ], [ [ 7.6322641819715, 28.887769423425, 0.0 ], [ 0.17364847088584, 0.98480770130976, 0.0 ] ], [ [ 7.8059126528574, 29.872577124735, 0.0 ], [ 0.17364847088584, 0.98480770130976, 0.0 ] ] ]
,

[ [ [ 2.8818741532637, -30.740819455584, 11.0 ], [ -0.17364847088584, 0.98480770130976, 0.0 ] ], [ [ 2.7082256823778, -29.756011754274, 11.0 ], [ -0.17364847088584, 0.98480770130976, 0.0 ] ], [ [ -7.6322559863329, 28.887773908675, 11.0 ], [ -0.17364788444799, 0.98480780471457, 0.0 ] ], [ [ -7.8059038707809, 29.872581713389, 11.0 ], [ -0.17364788444799, 0.98480780471457, 0.0 ] ], [ [ 7.8059126528574, -29.872577102383, 11.0 ], [ -0.17364847088584, 0.98480770130976, 0.0 ] ], [ [ 7.6322641819715, -28.887769401073, 11.0 ], [ -0.17364847088584, 0.98480770130976, 0.0 ] ], [ [ -2.7082169651985, 29.756013333797, 11.0 ], [ -0.17364788444799, 0.98480780471457, 0.0 ] ], [ [ -2.8818648496465, 30.740821138512, 11.0 ], [ -0.17364788444799, 0.98480780471457, 0.0 ] ] ]

]

V = [ v[0] for Tx in T for v in Tx ]

E = [ (i, i+1) for o, s in sumInterval(len(Tx) for Tx in T) for i in range(o, o+s) ]

import bpy

def createMesh(name, origin, verts, edges, faces):
    me = bpy.data.meshes.new(name+'Mesh')
    ob = bpy.data.objects.new(name, me)
    ob.location = origin
    ob.show_name = True
    bpy.context.scene.objects.link(ob)
    me.from_pydata(verts, edges, faces)
    me.update(calc_edges=True)
    return ob

createMesh("Tracks", (0,0,0), V,E,[])

This is the crash report :

# Blender 2.78 (sub 0), Commit date: 2017-02-24 14:33, Hash e92f235283
bpy.context.area.type = 'CONSOLE'  # Property
bpy.context.space_data.context = 'DATA'  # Property
bpy.ops.sculpt.sculptmode_toggle()  # Operator
bpy.ops.sculpt.sculptmode_toggle()  # Operator
bpy.ops.paint.vertex_paint_toggle()  # Operator
bpy.ops.paint.vertex_paint_toggle()  # Operator
bpy.ops.paint.weight_paint_toggle()  # Operator
bpy.ops.paint.weight_paint_toggle()  # Operator

# backtrace
blender(BLI_system_backtrace+0x30) [0x1412490]
blender() [0xa46459]
/usr/lib/libc.so.6(+0x33a90) [0x7fcd1c09ba90]
blender(bmesh_disk_edge_append+0) [0xfc3b70]
blender(BM_edge_create+0xda) [0xf9e83a]
blender(BM_mesh_bm_from_me+0x7ca) [0xfb2d4a]
blender(BKE_mesh_to_bmesh+0x87) [0x1173f37]
blender(EDBM_mesh_make+0x4d) [0xc86bcd]
blender(ED_object_editmode_enter+0x207) [0xcbf0a7]
blender() [0xcbf28d]
blender() [0xa4df0a]
blender() [0xa4e42d]
blender() [0xcbf40b]
blender() [0xa4df0a]
blender() [0xa4e42d]
blender() [0xc28922]
blender() [0xc39359]
blender() [0xa4f827]
blender() [0xa4fb48]
blender(wm_event_do_handlers+0x221) [0xa4fea1]
blender(WM_main+0x18) [0xa470a8]
blender(main+0x40f) [0xa2627f]
/usr/lib/libc.so.6(__libc_start_main+0xf1) [0x7fcd1c088511]
blender(_start+0x2a) [0xa4314a]

any idea ?

$\endgroup$
4
  • 1
    $\begingroup$ You have 32 vertices but your edges use vertex index from 0 to 32. You should range(o, o+s - 1) I think $\endgroup$ Commented Apr 3, 2017 at 14:37
  • $\begingroup$ Or E = [ (i, i+1) for i in range( len(V) - 1 ) ]? $\endgroup$ Commented Apr 3, 2017 at 15:16
  • $\begingroup$ Omg... yes, that's it, I forgot to correct on the script that... Thanks and sorry for my stupidity ^^ $\endgroup$ Commented Apr 3, 2017 at 17:08
  • $\begingroup$ Don't sorry... that happens to everyone! $\endgroup$ Commented Apr 3, 2017 at 17:19

1 Answer 1

2
$\begingroup$

I'm reposting the correct reply from @lemon so that it can be accepted as the answer as I had the same issue.

The code creating the edges based on the vertex list should be stopping at o+s-1 like so:

E = [ (i, i+1) for o, s in sumInterval(len(Tx) for Tx in T) for i in range(o, o+s-1) ]

Otherwise it's referencing a vertex that doesn't exist and Blender crashes when you switch to edit mode.

$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.