I'm learning OpenGL on Fedora 13 and noticed that a call to glGetString is causing a seg fault. I've scraped Google, but come up with no solutions.
The code is simple:
#include <GL/gl.h>
int main() {
glGetString(GL_VERSION);
return 0;
}
Compile Command:
g++ -lGL main.cpp -o test.bin
Run result:
$ ./test.bin
Segmentation fault (core dumped)
OpenGL Info:
$ glxinfo | grep OpenGL
OpenGL vendor string: Tungsten Graphics, Inc
OpenGL renderer string: Mesa DRI Intel(R) IGDNG_M GEM 20100328 2010Q1
OpenGL version string: 2.1 Mesa 7.8.1
OpenGL shading language version string: 1.20
OpenGL extensions:
Any ideas or references are greatly appreciated.
Solution:
#include <iostream>
#include <GL/freeglut.h>
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutCreateWindow("test");
glutFullScreen();
std::cout << glGetString(GL_VERSION) << std::endl;
return 0;
}
A segfault occurs when a reference to a variable falls outside the segment where that variable resides, or when a write is attempted to a location that is in a read-only segment.
Regarding Best practices to avoid segmentation faults, testing the code with tools like Valgrind/Efence helps in catching memory over runs. Besides using tools, writing and organising code carefully helps to great extent.
ANSWER. Signal 11, or officially know as "segmentation fault", means that the program accessed a memory location that was not assigned. That's usually a bug in the program. So if you're writing your own program, that's the most likely cause.
I doubt you can call even something as simple as glGetString without an OpenGL context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With