glutessellator尝试读取或写入受保护的内存

时间:2013-05-13 14:58:00

标签: c# access-violation glu

使用GLUtessVertexProc时,我在GLUtessellator回调时随机遇到了访问冲突异常,有人可以帮忙吗?非常感谢!这是主要代码:

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();
    }

}

1 个答案:

答案 0 :(得分:2)

当我使用dllimport从glu.dll导入命令时,我遇到了同样的问题。我没有设法解决它。最后,我在这里找到了GLU tesselation的C#端口:https://github.com/speps/LibTessDotNet,我直接使用它而不是从dll导入。

这个库足以满足我的需求。这可能是你的一个解决方案。