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

StackOverflow https://stackoverflow.com/questions/22591452

  •  19-06-2023
  •  | 
  •  

Question

I got an weird error on the Startup of my voxel engine.: Attempted to read or write protected memory. This is often an indication that other memory is corrupt

Init:

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

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

Gen:

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();
    }
Was it helpful?

Solution

This error indicates that you are calling OpenGL functions without a valid OpenGL context. If you build and run with a debug version of OpenTK.dll you will get a GraphicsContextMissingException instead.

Review your window construction code ensure no OpenGL calls are made before the context/window is constructed.

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