So here is the problem: When I call glGenTextures I get a segmentation fault.
I'm on linux, and here is the code I'm currently using to investigate this:
#include <iostream>
#include <SDL/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
int main(int argc, char *argv[])
{
GLuint texture;
glGenTextures( 1, &texture );
return texture;
}
Seems simple enough, right? Well, I traced the segfault with GDB (the GNU debugging tool) and it occurs when I call glGenTextures(), in the file /usr/lib/mesa/libGL.so.1.
That's my video driver's openGL code...
Any ideas?
It can be resolved by having a base condition to return from the recursive function. A pointer must point to valid memory before accessing it.
In practice, segfaults are almost always due to trying to read or write a non-existent array element, not properly defining a pointer before using it, or (in C programs) accidentally using a variable's value as an address (see the scanf example below).
A segmentation fault occurs when your program attempts to access an area of memory that it is not allowed to access. In other words, when your program tries to access memory that is beyond the limits that the operating system allocated for your program.
Use a #define or the sizeof operator at all places where the array length is used. Improper handling of NULL terminated strings. Forgetting to allocate space for the terminating NULL character. Forgetting to set the terminating NULL character.
The code as shown hasn't done anything to set up a valid OpenGL context, so it can't use OpenGL.
How to do this varies by platform. If you don't want to dig down in your target platform's way of doing this, you can use something like GLFW to do it fairly portably, but of course that adds a dependency.
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