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:

#include <stdlib.h>
#include <GL/glut.h>
#include <math.h>
#include <omp.h>
void render(void)
{
		int loop;
	#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:

gcc -o test test.c -lm -lglut -fopenmp -ggdb

Thanks for any replies.

Recommended Answers

All 2 Replies

void render(void)
{
		int loop;
	#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();
}

Invoking glVertex outside of a glBegin/glEnd pair results in undefined behavior.


[Edit:]
Some samples perhaps: Click here

Sorry, I forgot to add these into the testcase, though adding them doesn't work either - the problem persists.

The correct(still broken) testcase would then be:

#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();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.