Search code examples
c++visual-studioopenglsdlglew

SDL OpenGL app crashing in release mode


i am having a weird problem with opengl in visualstudio where every opengl function points to NULL if i build the program in release mode.

i have tried glew and gl3w none of them work

glew/gl3w is initialized after the context is created and in debug mode it runs fine

the project settings are default i only included the include folders and the respective lib folders

did anybody have a similiar issue?

#include<SDL.h>
#include<GL\glew.h>
#include<assert.h>

int main(int argc, char* args[])
{
    SDL_Init(SDL_INIT_VIDEO);

    SDL_Window *window;
    SDL_GLContext context;

    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);

    window = SDL_CreateWindow("Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
    context = SDL_GL_CreateContext(window);
    SDL_GL_MakeCurrent(window, context);
    glewExperimental = GL_TRUE;
    assert(!glewInit());

    GLuint id;
    glGenVertexArrays(1, &id);

    SDL_Quit();
    return 0;
}

Solution

  • assert(!glewInit());
    

    That isn't going to get compiled in Release mode. So glewInit() will never be called and glGenVertexArrays() will remain NULL.

    Calling a NULL function pointer generally won't work.