Question

I encountered an access violation exception randomly at GLUtessVertexProc callback when using GLUtessellator, can anyone help? many thanks! here is the main code:

public partial class Tessellation
    {
        [UnmanagedFunctionPointerAttribute(CallingConvention.StdCall)]
        public delegate void GLUtessVertexProc(IntPtr data);

    private List<Vector3> _buf = new List<Vector3>();
    private static readonly GLUtessVertexProc tessVertex = data => {
        double* dt = (double*)data;
        //exception occur...
        _buf.Add(new Vector3(dt[0], dt[1], dt[2]));
    };

    public List<Vector3> Tessellate(List<Vector3> outerBound)
    {
        _buf.Clear();

        GLUtesselator tess = GLU.gluNewTess();
        GLU.gluTessCallback(tess, GLU.GLU_TESS_BEGIN, tessBegin);
        GLU.gluTessCallback(tess, GLU.GLU_TESS_END, tessEnd);
        GLU.gluTessCallback(tess, GLU.GLU_TESS_ERROR, tessError);
        GLU.gluTessCallback(tess, GLU.GLU_TESS_VERTEX, tessVertex);
        GLU.gluTessCallback(tess, GLU.GLU_TESS_COMBINE, tessCombine);
        GLU.gluTessCallback(tess, GLU.GLU_TESS_EDGE_FLAG, tessEdgeFlag);
        GLU.gluTessProperty(tess, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_ODD);
        GLU.gluTessBeginPolygon(tess, IntPtr.Zero);
        //vertex data
        GLU.gluTessEndPolygon(tess);
        GLU.gluDeleteTess(tess);

        return _buf.ToList();
    }

}
Was it helpful?

Solution

I had the same problem as you when I used dllimport to import commands from glu.dll. I did not manage to solve it. Finally, I found the C# port of GLU tesselation here : https://github.com/speps/LibTessDotNet, and I used it directly instead of importing from dll.

This library is good enough for my needs. It might be probably one solution for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top