繁体   English   中英

C# 试图读取或写入受保护的 memory。 OpenGL/OpenTK 库

[英]C# Attempted to read or write protected memory. OpenGL/OpenTK libraries

我正在尝试执行以下代码:

static void Main(string[] args)
    {
        int Width = 512, Height = 512; //window size
        var CubeSize = 200; // square size
        int left, right, top, bottom;
        left = (Width - CubeSize) / 2;
        right = left + CubeSize;
        bottom = (Height - CubeSize) / 2;
        top = bottom + CubeSize;
        GL.ClearColor(0, 0, 0, 1);
        GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
        GL.Color3(255, 0, 0);
        GL.Begin(BeginMode.Quads);
        GL.Vertex2(left, bottom);
        GL.Vertex2(left, top); 
        GL.Vertex2(right, top);
        GL.Vertex2(right, bottom);
        GL.End();

    }

GL.ClearColor行中,它会引发错误:

试图读或写受保护的 memory

需要一些帮助。

要使用大多数 GL 方法,您需要在 GL 线程上。 判断您是否在 GL 线程上的最好方法是运行GameWindow是否调用了任何被覆盖的GameWindow方法。 如果要更改 GL 线程,则需要在不同的线程上创建一个新的 window ,然后使用window.MakeCurrent()

如果您在任何不同的地方使用它(例如,如果您从 GC 终结器中处理纹理),您可能会遇到该异常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM