freeglut fails to open display with valgrind

10,497

Solution 1

This is my guess: your IDE is probably missing the $DISPLAY environment variable. Somewhere you have to configure the environment to set $DISPLAY before launching Valgrind.

Launch a terminal and echo $DISPLAY. Its value is probably :0.0.

In the worst case, I'd try using setenv() inside the C code or set DISPLAY in the command line that launches Valgrind (none of these cases was tested, they may not work).

Solution 2

Also you have to add this environment variable DISPLAY:=0.0 inside Eclipse. In the launch configuration of your executable, add a Display variable to the Environment tab, or select to inherit environment.

Run->RunConfiguration...->Environment

Now click on

New

and add

DISPLAY :0

in it

Share:
10,497
dsnettleton
Author by

dsnettleton

Updated on June 04, 2022

Comments

  • dsnettleton
    dsnettleton almost 2 years

    I'm running the Eclipse IDE on Ubuntu 12.04 with the Valgrind plugin. I've been working on a game in C++ for quite some time, and I seem to have a memory error somewhere. Normally, I trace these with Valgrind. However, glut fails to initialize when I run valgrind. I should note that the game initializes without a problem when I'm not using valgrind. The code for my main function is as follows:

    int main(int argc, char** argv) {
      char windowTitle[12] = "Game Window";
      printf("Initializing Glut...\n");
      glutInit(&argc, argv);
      printf("Glut initialized!\n");
      alutInit(&argc, argv);
      Game_Object* game = new Game_Object(windowTitle, 1200, 675, argc, argv);
      delete game;
      printf("game ended\n");
      return 0;
    }
    

    The resulting output to the console is:

    Initializing Glut
    freeglut (/home/dsnettleton/Documents/Programming/Eclipse/workspace/Plutoids/Debug/Plutoids): failed to open display ''
    

    Obviously, the program isn't getting very far with valgrind running. It's really disheartening to be in such a final stage of my development, only to get stuck trying to weed out a memory error. What might be keeping glut from initializing, and what can I do to fix the problem?

  • dsnettleton
    dsnettleton almost 12 years
    That was it. I had to add the argument -DISPLAY=:0.0 to valgrind. Thank you so much; I was pulling my hair out.
  • amirkavyan
    amirkavyan about 10 years
    Smart. Thanks. Add new variable with these features: Variable : DISPLAY:0 VALUE: {leave empty}