cancel
Showing results for 
Search instead for 
Did you mean: 

SDK Discussions

cosmo909
Adept I

c# System.Runtime.InteropServices.SEHException

c# opentk replica of the GLInterop example works perfect for Mesh Objects under a certain amount of verts <42k but anything above and i get System.Runtime.InteropServices.SEHException on rprContextRender.

anyone have any idea why, i have loaded the objects in the c++ obj loader example and they are fine at 170k verts

Exception.png

0 Likes
1 Solution
cosmo909
Adept I

OK fixed it seems i was not supplying enough texture cords can now render objects with 170k+ verts 🙂 in Opentk without error

170k verts170k verts

View solution in original post

4 Replies
cosmo909
Adept I

OK fixed it seems i was not supplying enough texture cords can now render objects with 170k+ verts 🙂 in Opentk without error

170k verts170k verts

Hi!

I'm struggling to convert the tutorials into c# to learn the engine. Did you ever push any of your code into github or similar?

You've been a great helping in me work out how to add the framebuffer, but I'm struggling with the add mesh logic. (My c# is good, but my c++ is a bit meh.)

Any pointers would be useful!

0 Likes

Oh hi i dont use github,i havnt worked on that in a bit, but i did find my object loading code and did have problems with it at first its very particular  and you need to supply all data for an object in tri format ie. verts,faces,normals and uvs even if they are just fake uvs if your not using textures.i try comment stuff here you can work it out

void GetObjects()
{

//temp lists

List<Vector3> vertlist = new List<Vector3>();
List<int[]> facelist = new List<int[]>();

List<int[]> normIndeclist = new List<int[]>();
List<Vector3> normlist = new List<Vector3>();


//floor in thi case just a plane
objlist.Add(new Obj());
string pth = Application.StartupPath + "\\PrevObjects\\Floor.obj";

//LoadObj is just standard OBJ loading code
objlist[objlist.Count - 1].LoadObj(pth, 0);

//add verts

for (int dd = 0; dd < objlist[0].VertexList.Count; dd++)
{
vertlist.Add(
new Vector3(
(float)objlist[0].VertexList[dd].X,
(float)objlist[0].VertexList[dd].Y,
(float)objlist[0].VertexList[dd].Z));
}
int indcount = 0;
for (int dd = 0; dd < objlist[0].FaceList.Count; dd++)
{
int[] fc = new int[objlist[0].FaceList[dd].VertexIndexList.Length];
for (int i = 0; i < fc.Length; i++)
{
fc[i] = objlist[0].FaceList[dd].VertexIndexList[i];
}
facelist.Add(fc);
indcount += fc.Length;
}


//norms

for (int dd = 0; dd < objlist[0].NormList.Count; dd++)
{
normlist.Add(new Vector3(
(float)objlist[0].NormList[dd].X,
(float)objlist[0].NormList[dd].Y,
(float)objlist[0].NormList[dd].Z));

}
for (int dd = 0; dd < objlist[0].FaceList.Count; dd++)
{
int[] fc = new int[objlist[0].FaceList[dd].NormVertexIndexList.Length];
for (int i = 0; i < fc.Length; i++)
{
fc[i] = objlist[0].FaceList[dd].NormVertexIndexList[i];
}
normIndeclist.Add(fc);
}
//add make render object
int vcount = vertlist.Count;
float[] verts = new float[vcount * 3];
float[] norms = new float[normlist.Count * 3];
List<int> indec = new List<int>();

int gh = 0;


for (int i = 0; i < facelist.Count; i++)
{
int[] fc = new int[facelist[i].Length];
for (int ig = 0; ig < fc.Length; ig++)
{
indec.Add(facelist[i][ig]);
}
}
for (int i = 0; i < vcount; i++)
{
verts[gh] = vertlist[i].X;
verts[gh + 1] = vertlist[i].Y;
verts[gh + 2] = vertlist[i].Z;
gh += 3;

}
int st = 0;
for (int i = 0; i < normlist.Count; i++)
{
Vector3 n = normlist[i];
norms[st] = n.X;
norms[st + 1] = n.Y;
norms[st + 2] = n.Z;
st += 3;

}
//norms
List<int> norms_indec = new List<int>();
for (int i = 0; i < normIndeclist.Count; i++)
{
int[] fc = new int[normIndeclist[i].Length];
for (int ig = 0; ig < fc.Length; ig++)
{
norms_indec.Add(normIndeclist[i][ig]);
}
}

List<float> ctexcoord_data = new List<float>();

for (int i = 0; i < objlist[0].TextureList.Count; i++)
{

ctexcoord_data.Add((float)objlist[0].TextureList[i].X);
ctexcoord_data.Add((float)objlist[0].TextureList[i].Y);

}


List<int> ctexcoor_indices = new List<int>();

for (int dd = 0; dd < objlist[0].FaceList.Count; dd++)
{
int[] fc = objlist[0].FaceList[dd].TextureVertexIndexList;
for (int i = 0; i < fc.Length; i++)
{

ctexcoor_indices.Add(fc[i]);
}

}

int numc = 0;

Vector3 npos = new Vector3(0, 0, 0);
Vector3 nscale = new Vector3(1, 1, 1);

//call function to actually add object to Pro render

AddObject(
10,"Floor",npos.X, npos.Y, npos.Z, nscale.X, nscale.Y, nscale.Z,
verts, norms,
ctexcoord_data.ToArray(),
ctexcoor_indices.ToArray(),
indec.ToArray(), norms_indec.ToArray());

}


public void AddObject(uint ObjTID,string nme,float px,float py ,float pz,float sx,float sy,float sz,float[] verts_data,float[] norms_data,float[] ctexcoord_data,int[] ctexcoord_indices,int[] indices,int[] cnormal_indices)
{

Console.WriteLine("Add obj " + ObjTID);


int fnums = cnormal_indices.Length / 3;
int[] cnum_face_vertices = new int[fnums];

for (int i = 0; i < cnum_face_vertices.Length; i++)
{
cnum_face_vertices[i] = 3;
}


long vd = (long)(verts_data.Length / 3);
long vn = (long)(norms_data.Length / 3);
long cn = (long)(cnum_face_vertices.Length);
long tx = (long)(ctexcoord_data.Length);

//create mesh
Rpr.Check((int)Rpr.ContextCreateMesh(g_context,
verts_data, vd, 12,
norms_data, vn, 12,
ctexcoord_data, tx, 2,
indices, 4,
cnormal_indices, 4,
ctexcoord_indices, 4,
cnum_face_vertices, cn, out g_cube));

Rpr.Check((int)Rpr.SceneAttachShape(g_scene, g_cube));
RenderObjects.Add(new RenderObject(ObjTID, g_cube,nme));

}

 

 

 

 

Thank you! That's exactly what i needed to unblock. Appreciated!