   VBO code crashes
  I'm getting an issue where any code to do with VBOs is crashing. The error I get is:Quote:Unhandled exception at 0x00000000 in Growth Test.exe: 0xC0000005: Access violation reading location 0x00000000.The first piece of VBO code that is run is this:HeightMap::~HeightMap(){    GLenum er = glGetError(); // er == 0    if(glIsBuffer(bufferVertList))    {   clearVBO();    }}bufferVertList is 0 for this particular object.I've tried commenting out that function to see what would happen and it crashes at this code (glGenBuffers) instead:void HeightMap::createVBO(){    // Declare offsets, etc.    int mapSize = getMapSize();    int arraySize = sizeof(GLfloat) * mapSize * 9;    normalOffset = mapSize * 3;    textureOffset = mapSize * 6;    colourOffset = mapSize * 8;    // Give the vert list a buffer in memory.    glGenBuffers(1, &bufferVertList);I thought that it might be something to do with GLEW but I'm not really sure what to check - the glew32.lib and glew32.dll (v 1.3.4.0) files (and all glew source files) were copied from another project that worked fine. I'm calling glewInit() when I initialise my OpenGL Renderer class.Cheers.   
  Put a breakpoint on glewInit() and see if your program crashes before it hits. Are you using some OpenGL commands in a constructor of a static object? If these are called before glewInit I think your program can crash.   ;  glewInit only sets up extensions, are you sure you have OpenGL context established by the time glGenBuffers is called?   ;Quote:Original post by karwostsPut a breakpoint on glewInit() and see if your program crashes before it hits. Are you using some OpenGL commands in a constructor of a static object? If these are called before glewInit I think your program can crash.I tried what you suggested but it doesn't crash before glewInit(), even though my GLRenderer class is a Singleton.Here's the program's "set up" code:Logger::Initialise("log.txt");    // In case anything is added to texture cache initialisation    // later that requires explicit initialisation.    TextureCache::Initialise();    GLRenderer::Initialise(640, 480, 45.0f, 1.0f, 200.0f);GLRenderer& renderer = GLRenderer::Get();Window gameWindow(false, 640, 480, 16, "Growth Test App");    HWND hGameWindow; // create a handle to reference the window withhGameWindow = gameWindow.Initialise(hInstance); // create the window and return a handle to it// NOTE: The initialise member function/method of WindowCreator also creates the renderer// and makes it set up for rendering to the window.    // Seed random number generator.    Random::seed();    GameTimer timer;    // Initialise audio cache (sets up OpenAL).    //Audio_Cache::Initialise();    // The object that is responsible for the control (updating, rendering) of each game object.    //typedef boost::shared_ptr<Game> game_ptr;    //game_ptr game(new Game());    WeaponDatabase::Initialise("weapon_database.txt");    ProjectileManager::Initialise();    HeightMap map(getRandomDisplacement(50, 50, 0.0f, 0.8f)); // crashes on HeightMap dtorHere's the code that calls glewInit():void GLRenderer::Initialise(GLsizei rendererWidth, GLsizei rendererHeight,GLdouble fieldOfViewAngle, GLdouble nearClippingPlane, GLdouble farClippingPlane){    if(initialised)    {   LOG("Warning: GLRenderer is already initialised.");   return;    }    LOG("Initialising GLRenderer...");    glewInit();Here's another Singleton's code:void TextureCache::Initialise(){    if(!initialised)    {   LOG("Initialising TextureCache...");   ilInit();    initialised = true;    LOG("TextureCache initialised.");    }    else    {   LOG("Warning: TextureCache already initialised.");    }}Quote:Original post by i_luv_cplusplusglewInit only sets up extensions, are you sure you have OpenGL context established by the time glGenBuffers is called?Pretty sure:bool GLRenderer::BindToWindow(HWND &windowHandle){//set up pixel format, rendering context// NOTE: this method uses 'wgl' commands - the MS Windows Operating system binding for OpenGL.// it must be over-written when porting this renderer to another OS.// Need to do 5 things before we can use OpenGL// First - get the device context of the game window (ie. what is the window being shown on eg. graphics adapter)// Second - set that device to some desired pixel format// Third - create a rendering context for OpenGL (something OpenGL draws to and maps to the device)// Fourth - make the rendering context 'current'// Fifth - Set the size of the OpenGL window.// First - get the device context of the game windowhWnd = windowHandle;hDC = GetDC(hWnd); // get the device context of the window// Second - set the device to some desired pixel format// This is done be filling out a pixel format descriptor structurestatic PIXELFORMATDESCRIPTOR pfd; // pixel format descriptor// The pixel format discriptor has a lot of memembers (26) !// luckily we dont need most of them and set them to zero// we could go through the structure member by member and set them to zero// but a shortcut way is to use memset to Initialise everything to zeromemset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)); // sets all memmbers of pfd to 0// now we change only the relevant pfd memberspfd.nSize= sizeof(PIXELFORMATDESCRIPTOR);pfd.nVersion= 1;pfd.dwFlags= PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;pfd.cColorBits= 16;pfd.cDepthBits= 16;// based on the descriptor, choose the closest supported pixel format.int PixelFormat = ChoosePixelFormat(hDC, &pfd);if(PixelFormat==0){MessageBox (NULL,"Could not choose pixel format","Error",MB_OK);return (false);}// set the display device (device context) to the pixel formatif(SetPixelFormat(hDC, PixelFormat, &pfd)==0){MessageBox (NULL,"Could not set pixel format","Error",MB_OK);return (false);}// Third - create rendering context hRC = wglCreateContext(hDC); // windows dependent OpenGL function (wgl)    if(hRC == NULL)    {   MessageBox (NULL,"Could not create GL rendering context","Error",MB_OK);   return (false);    }    // Fourth - Make the rendering context currentif(!wglMakeCurrent(hDC, hRC))    {   MessageBox (NULL,"Could not make rendering context current","Error",MB_OK);   return (false);    }    // Fifth - set the size of the OpenGL window    /*    ***** Note: this step is important, not setting an initial size    can cause the whole OS to crash (computer is re-set)    */    RECT rect; // structure to store the coordinates of the 4 corners of the window    GetClientRect(hWnd, &rect); // put the window coordinates in the structure    ResizeCanvas(long(rect.right-rect.left), long(rect.bottom-rect.top)); return (true);};Quote:glewInit only sets up extensions, are you sure you have OpenGL context established by the time glGenBuffers is called?I think this should read "are you sure you have an OpenGL context established before you call glewInit". (Which it doesn't look like you do... try putting the renderer initialise call after the window initialisation).   ;Quote:Original post by sprite_houndQuote:glewInit only sets up extensions, are you sure you have OpenGL context established by the time glGenBuffers is called?I think this should read "are you sure you have an OpenGL context established before you call glewInit". (Which it doesn't look like you do... try putting the renderer initialise call after the window initialisation).I suck at all this OpenGL and Win32 crap... I'm just trying to understand how my lecturer has coded his stuff. I think that you may be right though?Oh... I get it now. I had refactored my lecturer's code in attempt to make it a bit less coupled... but stuffed up something. I get an error on this line in Window::Initialise():hMainWindow = CreateWindowEx(extendedWindowStyle, // 'extended style'wc.lpszClassName, // name of the windows class that we just registeredcaption.c_str(), // This text will appear at the top of the window in the title barwindowStyle, // Style of the window0, // x coordinate of upper east window corner0, // y coordinate of upper east window cornerWindowRect3.right - WindowRect3.left, // width of windowWindowRect3.bottom - WindowRect3.top, // height of windowNULL, // handle to the window's parent (no parent for our window)NULL, // handle to the window's menu (no menu for our window)hInstance, // handle to the application (as passed into WinMain)NULL // window creation data.   );The error says GL Renderer not initialised, which I guess occurs here:LRESULT Window::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){switch (message){    case WM_CREATE: // This message is sent when the window is first created    {    // the following calls the Instance method of the renderer class    // it returns a pointer to the renderer (if the renderer does not exist yet Instance creates it)    GLRenderer::Get().BindToWindow(hWnd); // ERROR HERE    break;    }// blah blah blah}If I set the GLRenderer's initialised variable to true, the program runs fine.Like you said, this is the order it should have been:    Window gameWindow(false, 640, 480, 16, "Growth Test App");   HWND hGameWindow; // create a handle to reference the window with    hGameWindow = gameWindow.Initialise(hInstance); // create the window and return a handle to it    // NOTE: The initialise member function/method of WindowCreator also creates the renderer    // and makes it set up for rendering to the window.    GLRenderer::Initialise(640, 480, 45.0f, 1.0f, 200.0f);Now just gotta figure out how to keep it looking nice while getting it to work haha.Cheers.[Edited by - Mybowlcut on April 20, 2010 5:18:35 AM]