You are invited to Log in or Register a free Frihost Account!

[OpenGL] glShaderSource segfault

We are using OpenGL in a course I take. Unfortunately the examples seem to be more aimed at windows so I have problems to get them to work on Linux. The program now compiles but when the call to glShaderSource is executed I get segfault. I have no idea what's wrong. I'm sure I call it with the right arguments. I see no reason for it to crash. It should just give an error message in case something is wrong.

Do you know how I can get it work? Is my graphics card too old? How do I know? Brick wall
Do you have a code snippet? I assume you're running the same versions of OpenGL?

I've been in a similar situation and the code I wrote seemed to be largely cross-compatible. Definitely no segfaults.
I noticed that I forgot a call to glCreateShaderObjectARB so now that gives segfault instead. Here is a reduced code snippet to just show the segfault:
#include "GL/glew.h"
#include "GL/glut.h"
#include "GL/glext.h"

static void displayFunction() {}

int main(int argc, char *argv[])
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutCreateWindow("Linux Test");
    GLhandleARB vertexShader = glCreateShaderObjectARB(GL_VERTEX_SHADER); // Segmentation fault
    const char* vv =
        "#version 130\n"
        "in  vec3 vertex;\n"
        "in  vec3 color;\n"
        "out vec3 outColor;\n"
        "uniform mat4 modelViewProjectionMatrix;\n"
        "void main()\n"
        "   gl_Position = modelViewProjectionMatrix*vec4(vertex,1);\n"
        "   outColor = color;\n"
    glShaderSource(vertexShader, 1, &vv, NULL);
    // ...
    return 0;

I am not sure if my hardware or driver support this but I don't expect it to crash. My card supports OpenGL 2 but I think the mesa driver don't support more than OpenGL 1.5. All these extension stuff confuses me. The course they say they use OpenGL 3 so I will probably never be able to do everything on my own computer anyway so maybe I should give up and go to a computer at school that I know can handle it..
I've never used glew (only glu), so I'm not sure what it's init() function is doing. However, what may be happenning is that you need to instantiate the openGL window/loop before certain functionality is available - otherwise it returns NULL and you get a segfault. I'm not sure why this would only happen on your Linux machine, perhaps the older version of openGL you have installed is less forgiving?

Out of interest, try putting a glutShowWindow() in after your calls to init() etc and see if it crashes or allows the rest to continue? If it can show the window openGL should have all functionality available.
glew is for handling OpenGL extensions. I see a window flashing by the screen but it disappears as soon as the the segfault comes (which is within milliseconds).
In that case I'm afraid I have no idea. You might be able to learn more by attaching a debugger and getting a stack trace.
Fire Boar
Run the command

ulimit -c unlimited

then open the core file using gdb. Alternatively, you can run the program using gdb ($ and (gdb) are both prompts):

$ gdb program
(gdb) run

And when it segfaults you get access to a lot of information. gdb is a pretty essential tool for programming, if you don't know about it then get Googling.
Related topics
GeForce G70 Preliminary Specifications
What computer languages you know?
Ever made one?
ATI vs Nvidia
Want to start making games?
RTCW:Enemy Territory OpenGL Issue
OpenGL enforce rendering speed [help please]
Problem with OpenGL
[Ubuntu] OpenGL
Is DirectX better or Opengl
Java 3D game programming and OpenGL
DirectX vs OpenGL
OpenGL: enlarge window but still get sharp pixels
Reply to topic    Frihost Forum Index -> Scripting -> Others

© 2005-2011 Frihost, forums powered by phpBB.