-1

Could anybodyy help me with this problem? I am trying to run an application using the cmakefiles. on the main file of my program I get a segmentation fault when the program gets to the line of code to execute the QAppication. Here is the fragment code below:

int main(int argc, char** argv)
{
bool viewing;
parse_command_line( argc, argv );

#ifdef _GRAPHICS_

  glutInit(&argc, argv);   // note the code runs correctly when this line is excluded and the glutInit was initialized in another class named Viewer (See class Viewer instantiated below), however for my specific application I need to initialize the glutInit in the main program
#endif

 if( viewing )
        {
#ifdef _GRAPHICS_
      QApplication application(argc, argv);
      Viewer    *viewer = new Viewer( 0, exp, argc, argv );
      Interface *render = new Interface( 0, exp, viewer );
      render->show();
      return application.exec(); //this line causes the segmentation fault
      delete viewer;
      delete render;
#endif
        }


}
Lekan Lanihun
  • 45
  • 1
  • 3

1 Answers1

0

When glutInit is called inside Viewer, application and viewer receive all the command line arguments. When you call it before, like you do, glutInit will eat all the parameters it understands, so the other objects might miss some arguments.

Possible solutions: do the glutInit (after application creation), or make a copy of argc/argv.

Ilya
  • 5,377
  • 2
  • 18
  • 33