Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Access Violation GLEW/GLFW3

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    14

    Access Violation GLEW/GLFW3

    Hello,

    I have the issue when following this tutorial..

    However when I do this:

    Code :
    unsigned int vbo = 0;
    glGenBuffers (1, &vbo);

    I get this:

    Code :
    Unhandled exception at 0x777ABDA1: 0xC0000005: Access violation executing location 0x00000000.

    And I have initiated glfw and glew..

    Any Suggestions?

    Many Thanks

    DoctorZeus

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    720
    Most likely glGenBuffers is not a valid function pointer, so the call fails. Possibly glew is not correctly initialized/encounters an error while initializing (do you set glewExperimental=TRUE before glewInit?) or your context creation does not work correctly.
    You'll have to post your code where you create the OpenGL context and initialize glew to say anything more specific.

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    14
    Quote Originally Posted by carsten neumann View Post
    Most likely glGenBuffers is not a valid function pointer, so the call fails. Possibly glew is not correctly initialized/encounters an error while initializing (do you set glewExperimental=TRUE before glewInit?) or your context creation does not work correctly.
    You'll have to post your code where you create the OpenGL context and initialize glew to say anything more specific.
    Thanks for the reply,

    Yes I have set glewExperimental to true before it is init..

    Here is my code to init and create a window:
    Code :
    bool CreateGraphicsWindow(unsigned int WindowSizeX, unsigned int WindowSizeY, char* WindowName = (char*)"MAIN WINDOW", bool fullScreen = false)
        {
    	glewExperimental=true;
            if (!glewInit() || !glfwInit())
            {
                TerminateNReturn((char*)"CANNOT INITALIZE GRAPHICS!");
                return false;
            }
     
            if (fullScreen)
                GraphicsWindow = glfwCreateWindow(WindowSizeX, WindowSizeY, WindowName, glfwGetPrimaryMonitor(), NULL);
            else
                GraphicsWindow = glfwCreateWindow(WindowSizeX, WindowSizeY, WindowName, NULL, NULL);
            if (!GraphicsWindow)
            {
                TerminateNReturn((char*)"CANNOT CREATE WINDOW");
                return false;
            }
     
            glfwMakeContextCurrent(GraphicsWindow);
     
            return true;
        }

    Many Thanks

    DoctorZeus

  4. #4
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    You have to initialize GLFW first. You need an active OpenGL context before you can load OpenGL functions or make any OpenGL calls.

    This means you need to initialize GLFW, set up your window properties, and then create a window. All before touching GLEW or anything in OpenGL.

  5. #5
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    14
    Quote Originally Posted by Alfonse Reinheart View Post
    You have to initialize GLFW first. You need an active OpenGL context before you can load OpenGL functions or make any OpenGL calls.

    This means you need to initialize GLFW, set up your window properties, and then create a window. All before touching GLEW or anything in OpenGL.
    Correct me if I am wrong (Noob alert with opengl here) but isnt glfw inialized with glfwinit() and the window created with glfwCreateGraphicsWindow?

    I can render basic shapes by specifying the coords using glBegin and glEnd and these render fine when entered in manually (I can render basic cubes and etc, etc..

    Thanks

    DoctorZeus

  6. #6
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    Correct me if I am wrong (Noob alert with opengl here) but isnt glfw inialized with glfwinit() and the window created with glfwCreateGraphicsWindow?
    Yes. And your call to "glewInit" comes before all of that. You have to initialize GLEW after creating the window, not before.

    I can render basic shapes by specifying the coords using glBegin and glEnd and these render fine when entered in manually (I can render basic cubes and etc, etc..
    That's because GLEW's macros pipe the GL 1.1 stuff through non-GLEW functions. Any functions from later GL versions will fail because GLEW has not been properly initialized yet.

  7. #7
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    14
    Quote Originally Posted by Alfonse Reinheart View Post
    Yes. And your call to "glewInit" comes before all of that. You have to initialize GLEW after creating the window, not before.



    That's because GLEW's macros pipe the GL 1.1 stuff through non-GLEW functions. Any functions from later GL versions will fail because GLEW has not been properly initialized yet.
    Ok that worked thanks!

    However I cannot see anything being rendered so will have a look into this!

    Many Thanks!

    DoctorZeus

  8. #8
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    14

    Again many thanks to everyone for their help..

    One more question, can someone please explain to me why this doesn't work (causes another access violation at a memory address, alsopTR->GetVertexes() returns a std::vector<float>)?

    Code :
        void AddObjectToRender(GraphicsStruc_Model *pTR)
        {
    		GLuint vertexBuffer;
    		if (pTR->ISMODELLOADED())
    		{
    			glEnableClientState(GL_VERTEX_ARRAY);
     
    			glVertexPointer(3, GL_FLOAT, 0, &pTR->GetVertexes());
    			glDrawArrays(GL_TRIANGLES, 0, pTR->GetVertexes().size());
     
    			glDisableClientState(GL_VERTEX_ARRAY);
    		}
        }

    I'm pretty sure it has something to do with vertex buffers and allocating memory but am totally lost in this regard..

    Could someone please be kind enough and explain it to me?

    Kind Regards

    DoctorZeus
    Last edited by doctorzeus; 08-08-2013 at 02:13 PM.

  9. #9
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    720
    Nothing to do with OpenGL directly. You are passing the address of a std::vector<float> to glVertexPointer, which is the address of the vector not the data it stores (which is what you want to pass to OpenGL) - you'd want &(pTR->GetVertexes().front()) for example. Additionally, your function returns the std::vector<float> by value (i.e. it makes a copy), so you are taking the address of a temporary that is deleted immediately after the glVertexPointer call - it's also inefficient because you keep copying the potentially large vertex data. Either assign the return value from GetVertexes() to a local variable (which still makes the copy, but keeps it alive until the end of scope):

    Code :
    std::vector<float> v = pTR->GetVertexes();
    glVertexPointer(3, GL_FLOAT, 0, &v.front());

    Or change your function to return a const reference (but make sure you understand what that does!):

    Code :
    struct GraphicsStruc_Model
    {
        const std::vector<float>& GetVertexes(void);
    }

    If any of this seems confusing, I'd recommend reading up on C++ object live time and memory management, you are likely to keep running into similar problems otherwise.

  10. #10
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    14
    Thanks for the reply!

    Luckily it all seems to make sense , I take it we obviously don't want it to create a new vector with a different memory address (as we want it to point to the start of the vector) so it is declared as constant. Also we don't want duplicated data in the memory.!

    Couldn't you also do this:

    Code :
    bool AddObjectToRender(GraphicsStruc_Model *pTR)
        {
    		GLuint numVertexes, numNormals, numTexturePoints;
     
    		if (pTR->ISMODELLOADED())
    		{
    			const float verteciesFront = pTR->GetVertexesFront();
    			numVertexes = pTR->GetVertexSize();
     
     
    			glEnableClientState(GL_VERTEX_ARRAY);
     
    			glVertexPointer(3, GL_FLOAT, 0, &verteciesFront);
    			glDrawArrays(GL_TRIANGLES, 0, numVertexes);
     
    			glDisableClientState(GL_VERTEX_ARRAY);
     
    			return true;
    		}
     
    		return false;
        }
     
    class GraphicsHandle
    {
            std::vector<float> vertexPoints, normalsPoints, texturePoints;
            const float GetVertexesFront()
    	{
    		return vertexPoints.front();
    	}
    };

    Unfortunately I am still having this issue, however it does work with some models! (Usually very small ones)..

    Of course I may be completely wrong! :P

    Kind Regards

    Doctorzeus

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •