Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Segmentation fault at glCreateShader in wxWidgets

📅 2014-Jul-22 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ error, glew, opengl, wxwidgets ⬩ 📚 Archive

Problem

I had a simple graphics program written using OpenGL and using GLUT for windowing. To get more windowing functionality, I wanted to move it to wxWidgets. I picked an example program that uses OpenGL in wxWidgets. It compiled and worked correctly. When I placed my OpenGL code into this example, I got a segmentation fault at the glCreateShader call in my code.

Solution

I had a glewInit in my original code. I had put this in the application class constructor. Apparently, wxWidgets requires that the first OpenGL or GLEW call be placed inside the OnPaint event handler function. Look for EVT_PAINT to find this function. Once I did that, the error disappeared and OpenGL worked.