grep
grep

Reputation: 4016

C++ access violation in opengl / glsl / sdl code

I am following some tutorials online regarding the GLSL. I have been implementing the code into my current program. It compiles just fine, but when I debug it, I get an access violation:

First-chance exception at 0x00000000 in Game Engine v0.2a.exe: 0xC0000005: Access violation.
Unhandled exception at 0x00000000 in Game Engine v0.2a.exe: 0xC0000005: Access violation.

I am not sure why. Here is the line it is pointing to:

GLuint v,f,f2,p,ge;
int gw = RESOLUTION_X;
int gh = RESOLUTION_Y;

void setShaders() 
{
    char *vs = NULL, *fs = NULL, *fs2 = NULL, *gs = NULL;

    v  = glCreateShader(GL_VERTEX_SHADER); //<-- this line
    f  = glCreateShader(GL_FRAGMENT_SHADER);
    ge = glCreateShader(GL_GEOMETRY_SHADER_EXT);

...

Do I need to provide any additional code? I'm just not sure what is being done wrong here.

Upvotes: 1

Views: 2616

Answers (2)

rodrigo
rodrigo

Reputation: 98328

I'd say that glCreateShader is a NULL pointer to function. This is a function that not all drivers support, so you should be using some kind of GL extension wrapper, such as the excellent GLEW.

And before using an extension you should check that it is supported by the current implementation: in your case it is a GL2.0 function so: if (GLEW_VERSION_2_0) ....

Upvotes: 1

user405725
user405725

Reputation:

Perhaps you forgot to call SDL_Init? Or maybe calling this function from multiple threads?

Upvotes: 2

Related Questions