Blender saves invalid mesh, how to debug

Hi Everybody,

Just hoping someone with more familiarity with the blender codebase can give me some pointers on how to debug something.

I managed to let blender save an invalid mesh to a blend file. The mesh displays fine in object mode, but as soon as I switch to editmode blender crashes.

I tracked it down to an edge of the mesh having an invalid node number, which is way larger than the number of vertices in the mesh.

Now I’d like to track down how the mesh ended up in this state (it happened while experimenting with some scripting), so I was wondering if there maybe was a build option to make blender check the validity of a mesh object. Or maybe a python command I can run from a script to check the validity of the vertex ids in the edge/face lists. Then I could insert it into my script periodically.

technical details:

in BM_mesh_bm_from_me ()

me->medge[i].v1 > me->totedge,

I’d like some way to notice immediately when that happens (as opposed to after saving).

If someone could point me in the right direction as to in which header file I should look for the declaration of struct Mesh that would be helpful as well, I’m a bit lost there as well…

1 Like

On the Mesh datablock, see validate() (ex: in Python Console: D.objects['Cube'].data.validate()).

By ‘node number’, you don’t happen to mean its index? Every vertex, edge and face has a unique index number (to the mesh), used to retrieve the element in sequences such as['Cube'].data.vertices[0] retrieving the first vertex of the default cube. In mesh editing, these elements are (briefly) assigned -1, which, interpreted as an unsigned, can be very large. Possibly, maybe, that is what you are seeing.

1 Like

I think I do, yes. It’s the value that’s used to index the vertex array in the Mesh struct.

I don’t think it was (unsigned)-1, I think I’d have recognized that ;-). But it I’ll check anyway.

What’s strange to me is that I can open the mesh in object mode, but as soon as it gets converted to a bmesh for edit mode it crashes. I’d think an invalid vertex index would make the object mode rendering code choke as well.

Thanks for the pointers I’ll do some more debugging.

1 Like