Why is mesh.from_pydata resulting in segmentation faults? I have vertex and face data loaded from a cube that was subdivided many times, with a total of 26138 vertices and slightly fewer faces.

I am loading the object in a script, and whenever I try to load it with mesh.from_pydata, I get a segmentation fault (core dumped) error.

mymesh = bpy.data.meshes.new(mesh_name)
myobject = bpy.data.objects.new(mesh_name, mymesh)


bpy.context.scene.objects.link(myobject)
print('loading from pydata...')
mymesh.from_pydata(vertices,[],faces)


vertices is either a numpy array or a list object. I've tried both, and the segmentation fault occurs in both. faces is a standard list of tuples corresponding to vertex indices.

Here is the log from /tmp/blender.crash.txt

 # Blender 2.78 (sub 0), Commit date: 2017-02-24 14:33, Hash e92f2352830
bpy.context.space_data.bookmarks_active = 0  # Property
   # backtrace
./blender(BLI_system_backtrace+0x1d) [0x19aad1d]
./blender() [0x104e2e6]
/lib/x86_64-linux-gnu/libc.so.6(+0x354b0) [0x7f720bccf4b0]
./blender() [0x19abc88]
./blender() [0x19ab12d]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x76ba) [0x7f720d2df6ba]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x6d) [0x7f720bda13dd]
The method from_pydata appears to be surprisingly brittle for something in Python. Something as simple as using a vertex index number that is out of bounds (number higher or equal to the number of vertices) will result in odd results followed by a segfault shortly after (for example by going from object mode to vertex mode).
Calling validate should at least prevent a segfault from happening. You'll have to look for what is exactly invalid with your parameters when calling from_pydata):
my_mesh.validate()

Edit: I spent a bit of time chasing segfaults with from_pydata myself until I eventually found reports such as the ones below. I don't imagine the use of it without validate since segfaults taking the whole process down are quite annoying.

https://developer.blender.org/T32773
https://developer.blender.org/T50199