Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 10

Thread: Weird segmentation faults when using OpenGL

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2012
    Posts
    4

    Weird segmentation faults when using OpenGL

    Hello,

    I'm learning to use modern OpenGL functionnalities (like Shaders and VBOs) at my university but I have some problems.

    First of all I'm using Ubuntu and this is what the command glxinfo | grep version show :
    Code :
    server glx version string: 1.4
    client glx version string: 1.4
    GLX version: 1.4
    OpenGL version string: 1.4 Mesa 8.0.2

    glxinfo | grep GL_ARB_VERTEX outputs the following :
    Code :
     GL_ARB_vertex_program, GL_ARB_vertex_shader, GL_ATI_draw_buffers, 
        GL_ARB_texture_non_power_of_two, GL_ARB_vertex_buffer_object, 
        GL_APPLE_object_purgeable, GL_ARB_vertex_array_object,
    so I have the ARB extensions allowing me to use VBOs.

    The problem now : the following code
    Code :
    #include <GL/glew.h>
    #include <GL/glut.h>
    #include <iostream>
     
    class Vec3{
    public:
    	float m_x;
    	float m_y;
    	float m_z;
     
    	Vec3(){}
    	Vec3(float x, float y, float z){
    		m_x=x;
    		m_y=y;
    		m_z=z;
    	}
    };
     
    GLuint VBO;
     
    static void CreateVertexBuffer()
    {
    	Vec3 vertices[1];
    	vertices[0] = Vec3(0.0f, 0.0f, 0.0f);
     
    	glGenBuffersARB(1, &VBO);
    	glBindBufferARB(GL_ARRAY_BUFFER, VBO);
    	glBufferDataARB(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
    }
     
    static void renderScene(){
    	glClear(GL_COLOR_BUFFER_BIT);
    	glEnableClientState(GL_VERTEX_ARRAY);
    	glVertexPointer(3, GL_FLOAT, 0, 0);
    	glDrawArrays(GL_POINTS, 0, 1);
    	glDisableClientState(GL_VERTEX_ARRAY);
    	glutSwapBuffers();
     
    }
    int main(int argc, char **argv) {
    	glutInit(&argc, argv);
    	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
    	glutInitWindowSize(400, 400);
    	glutInitWindowPosition(50, 50);
    	glutCreateWindow("Tutorial 2");
    	glutDisplayFunc(renderScene);
    	GLenum err = glewInit();
    	if (err != GLEW_OK){
    		std::cerr << "Error : " << glewGetErrorString(err) << std::endl;
    		return -1;
    	}
     
    	glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
    	CreateVertexBuffer();
    	glutMainLoop();
    	return 0;
    }

    Works fine, but if I replace the lines
    Code :
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(3, GL_FLOAT, 0, 0);
    glDrawArrays(GL_POINTS, 0, 1);
    glDisableClientState(GL_VERTEX_ARRAY);

    with the following :
    Code :
    glEnableVertexAttribArrayARB(0);
    glVertexAttribPointerARB(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
    glDrawArrays(GL_POINTS, 0, 1);
    glDisableVertexAttribArrayARB(0);

    I get a Segmentation fault. Anybody knows why ?

  2. #2
    Intern Contributor
    Join Date
    Jul 2006
    Posts
    72
    Forgot to load the function pointers?

  3. #3
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    The problem is here:

    Code :
    	glutDisplayFunc(renderScene);
    	GLenum err = glewInit();

    Once you start giving GLUT callback functions, it is free to call them at any time. Like, for example, immediately. But since you haven't finished loading OpenGL functions yet (ie: haven't called `glewInit`), you can't call those functions yet.

    In short, move the registration of `renderScene` until after you've initialized GLEW.

  4. #4
    Junior Member Newbie
    Join Date
    Oct 2012
    Posts
    4
    Quote Originally Posted by tanzanite View Post
    Forgot to load the function pointers?
    How do I do that ?

    Quote Originally Posted by Alfonse Reinheart View Post
    In short, move the registration of `renderScene` until after you've initialized GLEW.
    I switched the two lines, and the result is still the same.

  5. #5
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    Wait, I didn't see this:

    Code :
    OpenGL version string: 1.4 Mesa 8.0.2

    glVertexAttribPointer and the other generic attribute stuff wasn't core OpenGL until 2.0; until then, it came from ARB_vertex_shader. Naturally, they also had ARB suffixes.

    However, I'd be more concerned about the fact that your hardware seems to be limited to GL 1.4. Are you using some kind of older Intel hardware?

  6. #6
    Junior Member Newbie
    Join Date
    Oct 2012
    Posts
    4
    I'm using a Dell Inspiron Mini 10. The lspci -v command indicates in the VGA compatible controller section:
    Code :
    00:02.0 VGA compatible controller: Intel Corporation N10 Family Integrated Graphics Controller (prog-if 00 [VGA controller])
    	Subsystem: Dell Device 048e
    	Flags: bus master, fast devsel, latency 0, IRQ 43
    	Memory at f0200000 (32-bit, non-prefetchable) [size=512K]
    	I/O ports at 18d0 [size=8]
    	Memory at d0000000 (32-bit, prefetchable) [size=256M]
    	Memory at f0000000 (32-bit, non-prefetchable) [size=1M]
    	Expansion ROM at <unassigned> [disabled]
    	Capabilities: <access denied>
    	Kernel driver in use: i915
    	Kernel modules: i915

    Is it too old to use these functionalities ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •