[Bf-python] NMesh and edges

Chris Want cwant at ualberta.ca
Thu Apr 6 18:36:13 CEST 2006


I think there is some buggy code with the way that NMesh
handles edges.

I have written a simple exporter, and half of my objects
crash when entering editmode. The crash is during the routine
that converts edges into the editedge version, seemingly
on the last edge in the mesh (line 795, editmesh.c, turns
out that eed returns NULL on the preceding line).

In NMesh.c, fill_medge_from_nmesh(), there is a line that
looks like this:

  mesh->totedge=tot_valid_nmedges+tot_valid_faces_edges;

This number mesh->totedge determines how many
edges are malloced.

This line is followed by some code that copies
some edge information depending on a test on
the edge (edge-v1,edge->v2 not zero) so the
it potentially copies the edge data for less
than mesh->totedge meshes. For my crashing
meshes, the first edge of the mesh fails
the test, and this seems to be a problem,
since now the number of edges copied is less
than mesh->totedge.

I've revised the code so that it makes all of my meshes
read in OK, but it suffers the problem that mesh->totedges
is now less then the number of edges malloced:

   for ( i = 0, j = tot_valid_nmedges; i < tot_faces_edges; ++i )
   {
     MEdge *edge=faces_edges+i;
     if (edge->v1!=0 || edge->v2!=0)  // valid edge
     {
       MEdge *medge=mesh->medge+j;
       medge->v1=edge->v1;
       medge->v2=edge->v2;
       medge->flag=ME_EDGEDRAW|ME_EDGERENDER;
       medge->crease=0;
       ++j;
     }
	else {
		printf("goddam python %d\n", i);
		--mesh->totedge;
	}
   }

Anyways, I'd appreciate it if the original author of
this code revisited it -- this stuff gives me a
headache! Also, the indenting of this function is
done with spaces rather than tabs (tsk).

Chris



More information about the Bf-python mailing list