簡體   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