簡體   English   中英

OpenTK:嘗試讀取或寫入受保護的內存。 這通常表明其他內存已損壞

[英]OpenTK: Attempted to read or write protected memory. This is often an indication that other memory is corrupt

我的體素引擎啟動時出現一個奇怪的錯誤。:嘗試讀取或寫入受保護的內存。 這通常表明其他內存已損壞

在里面:

        public void initGL()
    {
        GL.Enable(EnableCap.CullFace); {<- Error}
        GL.Enable(EnableCap.Blend); {<- Error}

        GL.BlendFunc(BlendingFactorSrc.Src1Alpha, BlendingFactorDest.OneMinusSrc1Alpha); {<- Error}
    }

創:

public void genBlocks(float _px, float _py, float _pz, float _diameter, Universe _universe){
        this._planetPointer = GL.GenLists(1); {<- Error}
        GL.NewList(this._planetPointer, ListMode.Compile); {<- Error}

        GL.CullFace(CullFaceMode.Back); {<- Error}
        GL.PushMatrix();
        {
            for (int _y = 0; _y < _diameter; _y++)
            {
                for (int _x = 0; _x < _diameter; _x++)
                {
                    for (int _z = 0; _z < _diameter; _z++)
                    {
                        float _alt = (_x ^ 2) + (_y ^ 2) + (_z ^ 2);

                        if (_universe.getBlockB(_x, _y, _z, this) == 1 && (_universe.getBlockB(_x + 1, _y, _z, this) == 0 || _universe.getBlockB(_x, _y + 1, _z, this) == 0 || _universe.getBlockB(_x, _y, _z + 1, this) == 0 || _universe.getBlockB(_x - 1, _y, _z, this) == 0 || _universe.getBlockB(_x, _y - 1, _z, this) == 0 || _universe.getBlockB(_x, _y, _z - 1, this) == 0))
                        {
                            if (_alt > _diameter)
                            {
                                RenderBlock.renderBlock(_x, _y, _z, Block.stone, _universe, this.getBody());
                                Console.WriteLine("TESTEST");
                            }
                            else
                            {

                            }
                        }
                    }
                }
            }
        }
        GL.PopMatrix();
        GL.EndList();
    }

此錯誤表明您在沒有有效的OpenGL上下文的情況下調用OpenGL函數。 如果使用OpenTK.dll的調試版本進行構建和運行,則將獲得GraphicsContextMissingException

查看您的窗口構造代碼,確保在構造上下文/窗口之前不進行OpenGL調用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM