B2.5.4 mesh creation error. Bug?

I was writing a mesh generation script and I’ve runned into a problem. The script is pretty long and messy, but here is the part of code, which raises the error:


        verts=Generator()
        print(verts)
        mesh=bpy.data.meshes.new('Wall')
        mesh.from_pydata(verts,[],[])

Generator() method outputs list of tuples - coordinates. Below is an excerpt from output given by print(verts):


[(-3.5662245750427246, -0.07131103426218033, 3.492717742919922), (-2.8202550411224365, -0.07131103426218033, 4.105301380157471),
<.. more tuples here ..>
(-2.0920255184173584, 15.937682151794434, 5.054721832275391), (-3.013967752456665, 15.937682151794434, 5.550332546234131), (-3.818669080734253, 15.937682151794434, 6.211146831512451)]

To me it appears as a valid list of vertices’ coords. However this gives the following error:


Array length mismatch (expected 1296, got 1320).Traceback (most recent call last):
  File "/home/krizas/Downloads/blender25/2.54/scripts/addons/generate_log_walls.py", line 149, in invoke
    self.execute(context)
  File "/home/krizas/Downloads/blender25/2.54/scripts/addons/generate_log_walls.py", line 140, in execute
    mesh.from_pydata(verts,[],[])
  File "/home/krizas/Downloads/blender25/2.54/scripts/modules/bpy_types.py", line 315, in from_pydata
    self.vertices.foreach_set("co", verts_flat)
SystemError: internal error setting the array

From the description it seems to be a Blender’s bug. Or am I doing something wrong?
Full output can be found here.
I’m using Blender’s r32333 build.

Nevermind, by mistake I was trying to pass one 4D vector along 3D vectors.

I’ve found that using mesh.from_pydata() on an existing mesh will raise a similar error.

I was trying to redefine a mesh without having to unlink the mesh from the object, setting users to 0, unlinking from the scene and then recreating a new mesh and linking the new mesh to the object. I found that explicitly setting vertex coordinates using obj.data.vertices[vert_index].co = Vector(vert_coord) works well and appears to be faster.