Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I call
while (glGetError() != GL_NO_ERROR);
it gives the following exception:
Exception thrown at 0x00000000 in Application.exe: 0xC0000005: Access violation executing location 0x00000000.


And my error checking code is like this:
#pragma once
#include <glad/glad.h>
#include <iostream>

#define ASSERT(x) if (!(x)) __debugbreak();
#define GLCall(x) GLClearError(); x; ASSERT(GLLogCall(#x, __FILE__, __LINE__));

static void GLClearError();
static bool GLLogCall(const char* function, const char* file, int line);

static void GLClearError()
{
    while (glGetError() != GL_NO_ERROR);
}

static bool GLLogCall(const char* function, const char* file, int line)
{
    GLenum error = glGetError();

    if (error)
    {
        std::cout << "GL Error of type (" << error << ") at " << function << 
            " in file: " << file <<
            " called on line: " << line << std::endl;
        return false;
    }

    return true;
}


And I call it after calling
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{	
std::cout << "Failed to initialize GLAD" << std::endl;
	return -1;
}

glViewport(0, 0, 640, 480);

. And it seems like OpenGL is correctly initialized as I checked by printing out the GL_VERSION string.
Really confusing, not much else to say.

What I have tried:

I have only tried changing my initialization code, however that also failed.
Again, it is very unclear what do to so I only can barely do anything.
Posted

This is rather odd. Mostly because I have worked extensively with OpenGL and this is something I have never found necessary to do. You might have better success in finding out what the errors were and fixing them. I wrote this function a while ago and it has been useful for me. It generates a text string for the last error code. Here it is :
C++
///////////////////////////////////////////////////////////////////////////////
// generate an error string from the last OpenGL error along with a formatted message

int GetGLerrorMsg( PSTR buffer, int bufferSize, PCSTR format, ... )
{
    va_list args;
    va_start( args, format );

    int amount = vsnprintf( buffer, bufferSize, format, args );

    GLenum errorno = glGetError();
    if( errorno != GL_NO_ERROR )
        _sntprintf( buffer + amount, bufferSize - amount, " - %d: %s",
                    errorno, (PCSTR) gluErrorString( errorno ) );

    va_end( args );
    return errorno;
}
One caveat : it uses the GLU library to generate an error string for the message. This generates a text string with a user defined message along with a textual description of the error. Here is a sample of code that calls it :
C++
GetGLerrorMsg( buffer, bufferSize, "Call of wglCreateContext failed : " );
Note that it accepts variable arguments so you can pass practically anything that can be displayed. From there you can do what you want with the message string such as send it to a debugger, log it to a file, display on a console, etc.
 
Share this answer
 
You can see an answer from your error message text:
Exception thrown at 0x00000000 in Application.exe: 0xC0000005: Access violation executing location 0x00000000.

This means that your code call something at the address of 0x00000000. So somewhere you initialize the function pointer for example from the linked library or during initialization function, and that function pointer not set. So you miss call some function which set pointer or it missed due linked library not found or not compatible version of such library. Anyway you should perform step by step debugging and check on what function exception throwed and then check why the function pointer you have called not initialized.

Regards,
Maxim.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900