# glGenVertexArrays causes crash

My code keeps crashing at runtime, I have done some creative debugging and determined that it was the glGenVertexArrays that was causing the crash, I've looked around and come across some answers that told me to enable experimental mode in GLEW but that didn't work, as far as I can tell my graphics card supports it, my opengl version is 3.1. I'm using freeGLUT and GLEW

here's the code, the line in question is 45 http://hastebin.com/rekizejuza.cpp

std::cout << "made it here\r\n";
glGenVertexArrays(1, &meshID);
std::cout << "not here here\r\n";
glBindVertexArray(meshID);

• Can you show your code? – Appleshell Apr 22 '14 at 23:22
• Just edited the question to include the code – Jordan LaPrise Apr 23 '14 at 0:14
• @JordanLaPrise You need to include the code into the question itself! – Vallentin Apr 23 '14 at 0:37
• BTW, looking at the code provided in the link, I've spotted another error, which doesn't seem to be related to the glGenVertexArrays problem, but nonetheless would crash your app if it wen't on. Check line 57 delete [] ids;. You are deleting a local variable that was declared on the stack, at line 49 unsigned int ids[4];. Your compiler is probably not complaining about it, but this is absolute nonsense. – glampert Apr 23 '14 at 18:48
• Hello my friend! Probably you forgot to add glewExperimental = GL_TRUE; and this causes openGL crashes when calling glGenVertexArrays(); I hope I have helped! See ya! – Michael Pacheco Jul 25 '17 at 1:32

A common reason for null pointer dereferences on calls to newer OpenGL functions is that they are provided by an extension wrangler library like GLEW through function pointers that are dynamically loaded at runtime.

In order for them to be initialized, you need to run the initialization function of GLEW.

The correct place to call glewInit() is after you've gotten an OpenGL context and have made it current, but before you use any of the extension function pointers it exposes.

• I did run glewInit, I'm using it with freeGlut, so would the right place to init glew be after I've created the window but before I've started the event loop? – Jordan LaPrise Apr 23 '14 at 14:31
• Yes, right after freeGLUT is up would be a good place to call it. Make sure to check the return value for any initialization error. – glampert Apr 23 '14 at 18:36

You mentioned to be using GLEW. If so, the glGenVertexArrays symbol should be just a plain global variable of type function pointer. To know if it is available, you can just test it for null:

if (glGenVertexArrays == NULL)
{
// chances are you don't have this feature...
}


If it is null, then either you have a problem with GLEW or the feature is likely not supported in your system.

In case you don't have VAOs, you can still render pretty much in the same way. Just remove the VAO calls and remember to always reset the vertex format before drawing. I.e.: glVertexAttribPointer.

Also, Make sure you have the most recent GL diver. It might help.

• Well crap, it says it's not supported but I have gl 3.1 and from what I understood VAOs were introduced in 2.1 why would I not have them? – Jordan LaPrise Apr 23 '14 at 2:33
• Oh nvm, I tried calling it after initializing GLEW and it wasn't null – Jordan LaPrise Apr 23 '14 at 2:35
• What about glGetError() did it return anything before/after the failure? – glampert Apr 23 '14 at 3:40
• no error before, if an error happened after I wouldn't know because the entire program comes to a halt and stops responding at that point – Jordan LaPrise Apr 23 '14 at 4:06
• Is the problem fixed now? If yes, mark the answer correct. – Jari Komppa Apr 23 '14 at 5:37