Segfault in GLUTs glVertex2f()

General OpenMP discussion

Segfault in GLUTs glVertex2f()

Postby kuratkull » Sun Jul 27, 2008 12:39 pm

Hello,

I am having a problem with a Glut function which is messed up, either by GCC or by OpenMP.
I have GCC 4.3.1 20080626.

The problem is, that I do not know which of the three is causing the "Segmentation fault" at the glVertex2f() function. The proggie works perfectly when in single-core mode.

I have written a testcase for this:
Code: Select all
#include <stdlib.h>
#include <GL/glut.h>
#include <math.h>
#include <omp.h>
void render(void)
{
      int loop;
      glClear(GL_COLOR_BUFFER_BIT);
      glBegin(GL_POINTS);
      #pragma omp parallel shared(loop)
      {
       #pragma omp for
       for (loop = 0; loop < 100; loop++)
         {
          printf("DIE\n");
               _flushlbf ();
          glVertex2f(loop/50.0,loop/50.0);
         }
      }
      glEnd();
      glFlush();
}


int main (int *argc, char **argv)
{
 
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
  glutInitWindowPosition(50,50);
  glutInitWindowSize(800,800);
  glutCreateWindow("Fallzorz");
  glutDisplayFunc(render);
  glutMainLoop();
}


Compile with:
Code: Select all
gcc -o test test.c -lm -lglut -fopenmp -ggdb


Thanks for helping me out.
kuratkull
 
Posts: 2
Joined: Sun Jul 27, 2008 12:34 pm

Re: Segfault in GLUTs glVertex2f()

Postby ejd » Mon Jul 28, 2008 8:52 am

Are you sure that glut is thread-safe?? From a quick search on the web, it would appear that it isn't (though the glut web site doesn't seem to address that question). I believe this is the cause of your problem.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: Segfault in GLUTs glVertex2f()

Postby kuratkull » Mon Jul 28, 2008 9:05 am

Hmm, you may be right, since GLUT is a rather complicated system.
Thanks for the reply :)
kuratkull
 
Posts: 2
Joined: Sun Jul 27, 2008 12:34 pm


Return to Using OpenMP

Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests