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 4 of 4

Thread: [Linux C programming] segmentation fault

  1. #1
    Newbie Newbie
    Join Date
    Oct 2015
    Posts
    4

    [Linux C programming] segmentation fault

    Greetings !!

    I already dig the internet but failed to find a solution concerning this simple program expected to initialize the glut context...

    Code :
    #include <stdio.h>
    #include <stdlib.h>
     
    // Librairie opengl
     
    #include <GL/gl.h>
    #include <GL/glut.h>
     
    int windowID;       
     
     
    int main(int argc,char* argv[],char *envp[]) 
    {
      glutInit(&argc,argv); 
      glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
      glutInitWindowSize(1024,768);                                                                                                                
      windowID = glutCreateWindow("Not utf8 -- premiŤre fenÍtre en opengl !!");
      glutFullScreen();
     
      exit(0);
     }

    When debugging, I can see the window opened (that how I can say that the window title does not handle the utf8).
    When executing, nothing happened and I got a segmentation fault happening at line 33 (that points to the glutInit() call).

    When debugging the SIGSEGV (segmentation fault) signal is sent when program is exiting... all the main functions seem to be executed without any problem.

    I know that argc is modified as glutInit extracts any command line options intended for the GLUT library.

    I have nothing to pass, for now, to the application, so argc must be 1 and argv to NULL.

    What is wrong ? Did I forgot something ?

  2. #2
    Intern Newbie
    Join Date
    May 2015
    Posts
    37
    Did I forgot something ?
    Yup, two things. Namely, glutMainLoop and glutDisplayFunc.
    Code :
    #include <stdio.h>
    #include <stdlib.h>
     
    // Librairie opengl
     
    #include <GL/gl.h>
    #include <GL/glut.h>
     
    int windowID;
     
    void disp() {                     /// added
        glClear(GL_COLOR_BUFFER_BIT); /// added
        glutSwapBuffers();            /// added
    }                                 /// added
     
    int main(int argc,char* argv[],char *envp[]) {
        glutInit(&argc,argv);
        glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
        glutInitWindowSize(1024,768);
        windowID = glutCreateWindow("Not utf8 -- premiŤre fenÍtre en opengl !!");
        glutFullScreen();
        glutDisplayFunc(disp);        /// added
        glutMainLoop();               /// added
        exit(0);
    }

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,742
    https://www.opengl.org/documentation...c3/node16.html - glutCreateWindow is specified as taking an ASCII string. "premiŤre fenÍtre" certainly doesn't contain ASCII characters, so I suggest that you correct what is obviously wrong first.

  4. #4
    Newbie Newbie
    Join Date
    Oct 2015
    Posts
    4
    Big thanx !! I'll try it once at home ^^

Posting Permissions

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