0
\$\begingroup\$

When I try to debug my program, this Exception is being thrown in a call to glGenBuffers. I'm using OpenGL and SDL. Here is my code:

It consists of two classes: m and sprite

s is var of sprite class

class m is like this:

void run()
{
    init();
    s.init(-1.0f,-1.0f,1.0f,1.0f);
    loop();
}


void  init()
{
    SDL_Init(SDL_INIT_EVERYTHING);
    glewExperimental = GL_TRUE;
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    window = SDL_CreateWindow("mine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1024, 768, SDL_WINDOW_OPENGL);
    if (window == nullptr) {

        fatalerror("cant create (open) window");
    }

    SDL_GLContext context = SDL_GL_CreateContext(window);
    if (context == nullptr) {

        fatalerror("context cant be created ");


    }
    GLenum cerror = glewInit();
    if (cerror != GLEW_OK)
    {
        fatalerror("cant init glew:(");
    }
    std::cout << "ok";


    glClearColor(1.0f, 0.0f, 0.0f, 1.0f);


}

void looploop()
{
    while (state != gamestate::exit)
    {

        input();
        draw();
    }

}
void M::input()
{
    while (SDL_PollEvent(&events)) {

        switch (events.type)
        {
        case SDL_QUIT:
            state = gamestate::exit;
            SDL_DestroyWindow(window);
            break;
        case SDL_MOUSEMOTION:
            std::cout << events.motion.x << ',' << events.motion.y << "\n";
            break;
        }



    }

}

void draw()
{
    glClearDepth(1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnableClientState(GL_COLOR_ARRAY);
    s.draw();

    SDL_GL_SwapWindow(window);

}

class sprite:

void init(float x, float y, float w, float h)
{
    _x = x;
    _y = y;
    _w = w;
    _h = h;

    if (vboid == 0) {


        glGenBuffers(1, &vboid);
    }

    float vertexdata[12];
    //first triangle
    vertexdata[0] = x + w;
    vertexdata[1] = y + w;
    vertexdata[2] = x;
    vertexdata[3] = y + h;
    vertexdata[4] = x;
    vertexdata[5] = y;
    //second triangle
    vertexdata[6] = x;
    vertexdata[7] = y ;
    vertexdata[8] = x+h;
    vertexdata[9] =  y;
    vertexdata[10] = x+w;
    vertexdata[11] = y+h;
    glBindBuffer(GL_ARRAY_BUFFER,vboid);
    glBufferData(GL_ARRAY_BUFFER,sizeof(vertexdata),vertexdata,GL_STATIC_DRAW)
        ;

}


void draw()
{


    glBindBuffer(GL_ARRAY_BUFFER,vboid);
    glEnableVertexAttribArray(0);
    glVertexAttribLPointer(0,2,GL_FLOAT,GL_FALSE,0);
    glDrawArrays(GL_TRIANGLES,0,6);
    glDisableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, vboid);

}
\$\endgroup\$
  • \$\begingroup\$ Where is vboid defined? If that were either null or part of an object that was deleted, it could cause this problem. \$\endgroup\$ – user1118321 Aug 18 '18 at 4:07
  • \$\begingroup\$ 0x00000000 is a NULL pointer; from what you say, the glGenBuffers function pointer seems to not be set. What hardware have you? \$\endgroup\$ – Maximus Minimus Aug 18 '18 at 8:22
  • \$\begingroup\$ thanks for answer vboid equals to zero in the constructor maybe its the hardware \$\endgroup\$ – Ahmed Fathy Aug 18 '18 at 14:59
  • \$\begingroup\$ my display adapter is Intel(R) G41 Express Chipest(Microsoft Corporation-WDDM1.1) \$\endgroup\$ – Ahmed Fathy Aug 18 '18 at 15:18
  • \$\begingroup\$ i have 2GB ram ,my processor is Intel pentium(R) pentium(R)4 CPU 3.20GHZ,my operation system is windows 7 32bit \$\endgroup\$ – Ahmed Fathy Aug 18 '18 at 15:28
1
\$\begingroup\$

Let me guess, you're on ms windows?

You need to "wrangle the OpenGL extension" using GLEW. Personally, I use OpenGL Core Profile, and use GL3W to do this for me on the windows platform.

Without doing glewInit() or gl3wInit() first, your extension function pointers are all nil, hence the crash.

On all other platforms (Linux, MacOS, etc) this is not necessary. Root cause for this is Microsoft's Installable Client Driver model.

\$\endgroup\$
  • \$\begingroup\$ I used glewinit but it didn.t solve the problem \$\endgroup\$ – Ahmed Fathy Aug 18 '18 at 20:55
  • \$\begingroup\$ could this Exception thrown due to the oldness of my hardware or not \$\endgroup\$ – Ahmed Fathy Aug 19 '18 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.