3
\$\begingroup\$

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);
\$\endgroup\$
  • 1
    \$\begingroup\$ Can you show your code? \$\endgroup\$ – Appleshell Apr 22 '14 at 23:22
  • \$\begingroup\$ Just edited the question to include the code \$\endgroup\$ – Jordan LaPrise Apr 23 '14 at 0:14
  • \$\begingroup\$ @JordanLaPrise You need to include the code into the question itself! \$\endgroup\$ – Vallentin Apr 23 '14 at 0:37
  • \$\begingroup\$ 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. \$\endgroup\$ – glampert Apr 23 '14 at 18:48
  • \$\begingroup\$ 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! \$\endgroup\$ – Michael Pacheco Jul 25 '17 at 1:32
8
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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? \$\endgroup\$ – Jordan LaPrise Apr 23 '14 at 14:31
  • \$\begingroup\$ 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. \$\endgroup\$ – glampert Apr 23 '14 at 18:36
2
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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? \$\endgroup\$ – Jordan LaPrise Apr 23 '14 at 2:33
  • \$\begingroup\$ Oh nvm, I tried calling it after initializing GLEW and it wasn't null \$\endgroup\$ – Jordan LaPrise Apr 23 '14 at 2:35
  • \$\begingroup\$ What about glGetError() did it return anything before/after the failure? \$\endgroup\$ – glampert Apr 23 '14 at 3:40
  • \$\begingroup\$ 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 \$\endgroup\$ – Jordan LaPrise Apr 23 '14 at 4:06
  • \$\begingroup\$ Is the problem fixed now? If yes, mark the answer correct. \$\endgroup\$ – Jari Komppa Apr 23 '14 at 5:37

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.