PDA

View Full Version : [Linux C programming] segmentation fault



hurukan
10-07-2015, 05:23 PM
Greetings !!

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


#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 ?

hidefromkgb
10-08-2015, 04:16 AM
Did I forgot something ?Yup, two things. Namely, glutMainLoop (https://www.opengl.org/documentation/specs/glut/spec3/node14.html) and glutDisplayFunc (https://www.opengl.org/documentation/specs/glut/spec3/node46.html).

#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);
}

mhagain
10-08-2015, 05:15 AM
https://www.opengl.org/documentation/specs/glut/spec3/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.

hurukan
10-08-2015, 11:19 AM
Big thanx !! I'll try it once at home ^^