Results 1 to 3 of 3

Thread: Segmentation fault on glClearBuffer*

  1. #1
    Newbie Newbie
    Join Date
    Sep 2013

    Segmentation fault on glClearBuffer*

    I'm trying to go through the OpenGL SuperBible 6th ed., but was having a bit of trouble using the provided sb6.h framework for setting up windows and whatnot. I have done some legacy OpenGL using GLFW for windowing, so I figured I could just wrap the code in GLFW rather than what the book provides.

    However, I am segfaulting whenever I reach glClearBufferfv:

    Code :
    #include <GL/glew.h>
    #include <GLFW/glfw3.h>
    #include <stdlib.h>
    #include <stdio.h>
    static void errorCallback(int error, const char *description)
      fputs(description, stderr);
    static void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
      if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
        glfwSetWindowShouldClose(window, GL_TRUE);
    static const GLfloat red[] = { 1.0f, 0.0f, 0.0f, 1.0f };
    int main(void)
      glewExperimental = true;
      GLFWwindow *window;
      if (!glfwInit()) {
        return EXIT_FAILURE;
      window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL);
      if (!window) {
        return EXIT_FAILURE;
      glfwSetKeyCallback(window, keyCallback);
      int width, height;
      glfwGetFramebufferSize(window, &width, &height);
      glViewport(0, 0, width, height);
      int maxBuffers = 0;
      glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxBuffers);
      printf("GL_MAX_DRAW_BUFFERS = %d\n", maxBuffers);
      while (!glfwWindowShouldClose(window)) {
        glClearBufferfv(GL_COLOR, (GLint) 0, red);
      return EXIT_SUCCESS;

    According to my glewinfo, my hardware supports up to GL_VERSION_4_0, but I'm guessing I'm missing something else. According to the OpenGL reference, glGetError() should be flagged, but when I set up a sigaction to caught the segfault, I got GL_NO_ERROR. Any help would be appreciated.

  2. #2
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    You are initializing GLEW before creating an OpenGL context (AFAIK GLFW does that as part of glfwCreateWindow). Since GLEW needs to query the OpenGL context for (extension) functions you must initialize GLEW after creating the OpenGL context and making it current.

  3. #3
    Newbie Newbie
    Join Date
    Sep 2013
    That was it. Thank you!

Similar Threads

  1. Segmentation fault with cl2.hpp
    By Mike Zhang in forum OpenCL
    Replies: 0
    Last Post: 02-03-2017, 12:22 AM
  2. Segmentation fault
    By genericname in forum OpenGL: Windows
    Replies: 3
    Last Post: 03-11-2012, 10:01 AM
  3. Segmentation fault while using PBO
    By SagoO in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-03-2011, 08:03 AM
  4. Segmentation fault
    By kmn2446 in forum OpenGL: Linux
    Replies: 4
    Last Post: 03-16-2004, 08:53 AM
  5. Segmentation fault
    By D1G1T4LL in forum OpenGL: Linux
    Replies: 2
    Last Post: 12-09-2003, 08:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean