@Rick:
Your CreatePatch function creates triangles with vertices that don't exist, hence the access violation.
It should read
"z <= zegs" and "x <= xsegs" like the framewerk function:
TMesh CreatePatch(int xsegs, int zsegs)
{
int x,z;
TMesh mesh;
int count;
TSurface surf;
mesh=CreateMesh();
surf=CreateSurface(mesh);
for(z=0;z<=zsegs;z++)
{
for(x=0;x<=xsegs;x++)
{
count=AddVertex(surf,
Vec3( (flt)(x)/(flt)(xsegs)-0.5f, 0, (flt)(z)/(flt)(zsegs)-0.5f ),
Vec3( 0, 1, 0),
Vec2( (flt)(x)/(flt)(xsegs), 1- (flt)(z)/(flt)(zsegs) ));
if( (x>0) && (z>0) )
{
AddTriangle(surf, count-1, count, count-xsegs-1);
AddTriangle(surf, count-1, count-xsegs-1, count-xsegs-2);
}
}
}
UpdateMesh(mesh);
return mesh;
}